Tuesday, 23 April 2013

Google App Engine Simple tutorial

Step 1:

In Eclipse 

Help->install new Application->Work With

Google application  - http://dl.google.com/eclipse/plugin/3.7


Step 2:

Create  Google App Web Project.















Name this Project And select Check box






















Finish


Step 3:

Ctreate Simple JSP Page and Place control on it.

for eg Tax.Jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Tax Project</title>
</head>
<body>
<h1>Tax Calculation</h1>
<center>
<form action="taxcalulation" method="get">
Enter Amount <input type="text" id="amount" name="amount"/>
<input type="submit" value="Tax">
</form>
</center>
</body>
</html>

Step 4:

Create Servlet  And Mapping to web.xml


Step 5:

Write code on Servlet
for eg.


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("out");
int tax=Integer.parseInt(request.getParameter("amount"));
System.out.println(tax);
int val=0;
if(tax <= 20000)
{
val=0;
}
else
if(tax >= 20000 && tax <= 30000)
{
val=tax/10;
}
else
{
val=tax/30;
}
response.setContentType("text/plain");
response.getWriter().println("Tax Amount="+val);

}


Step 6:

Run the program on  (G)  Web Application 


















Console output Lite this 
















Dev App Server is running.....

Step 7:

Open Browser
And  write into address bar
http://Localhost:8888

Show the home page
















Click Tax Calculation

Open tax.jsp










Enter Amount And Click Tax button

Show the result











Done......



Sunday, 21 April 2013

AutoComplet TextBox (MultiValue)

Step 1:
create JSP Page and add Control on Page












Step 2:
Create a array list and add mail id on array list

for eg

 public static  ArrayList<String> usermail()
                 {
                ArrayList<String> list11=null;
                try {
                   list11 = new ArrayList<String>();
                if(con.isClosed())
{
openConnection();
}
                   String Query="SELECT Email FROM personal_info";
                   statement=con.createStatement();
                   ResultSet rs=statement.executeQuery(Query);
                   System.out.println(Query);
                 while(rs.next())
                 {
                            list11.add(rs.getString("Email"));
                             }
                }catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
                                
             return list11;
                 }


Step 3:
Access array list On JSP Page
import class on JSP page

<%@ page import="java.util.*,util.*,dao.*;" %>
<%
  ArrayList<String> usermail= VisitorOutPassDAO.usermail();
%>

Step 4:
Given code on Java script


<script type="text/javascript">
$(function() {
var availableTags= new Object([]);
<%! int i=0;%>
<%
for(i=0;i<usermail.size();i++)
{
%>
availableTags[<%= i %>]='"<%= usermail.get(i) %>"';
<%}%>
//availableTags = availableTags.substring(0, availableTags.length - 1);
//availableTags+="]";
alert(availableTags);
    function split( val ) {
     return val.split( /,\s*/ );
   
  }
  function extractLast( term ) {
    return split( term ).pop();
  }

  $( "#mailId" )
//don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "ui-autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
//delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
//prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );

//remove the current input
terms.pop();
//add the selected item
terms.push( ui.item.value );

var selected_cust_name=ui.item.value;
var all_selected_cust=$("#mailId").val();
var index=all_selected_cust.indexOf(selected_cust_name);
//add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( "," );
if(index!=-1)
{
all_selected_cust=$("#mailId").val();
var all_len=all_selected_cust.length;
var seleced_len=selected_cust_name.length;
seleced_len++;
var last_index=all_len-seleced_len;
if(last_index!=0)
{
var final_value=all_selected_cust.substring(0,last_index);
$("#mailId").val(final_value);
}
alert("Already selected.");
}
return false;
}
});
});
}
</script>

Out Put








Thursday, 18 April 2013

Sending Email Using JSP Servlet

Step 1: 
Create JSP file 
















Step 2:
Write a Script Code To call Servlet.


function sendmail()
{
waiting_effect_on();
alert("send mail");
$.ajax({ type: "Post", url: "send_message",
data:{mailId:$("#mailId").val(),subject:$("#subject").val(),message:$("#message").val()},
cache:false,
success : function(data){
waiting_effect_off();
alert(data);

}
});
}



Step 3:
Write given code to Servlet.


               Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Session mailSession = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("XXXXX@gmail.com", "*****");
}
});
Message simpleMessage = new MimeMessage(mailSession);


       InternetAddress fromAddress = null;
       InternetAddress toAddress = null;
       try {
           fromAddress = new InternetAddress(Email);
           toAddress = new InternetAddress(mailId);
       } catch (AddressException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }

       try {
           simpleMessage.setFrom(fromAddress);
           simpleMessage.setRecipient(RecipientType.TO, toAddress);
           simpleMessage.setSubject(subject);
           simpleMessage.setText(message1);

           Transport.send(simpleMessage);
       } catch (MessagingException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }



Step 4:
Run JSP File and insert input fields















Step 4:
Check Mail To your Account









You Want to attach file into mail then replace code to this code

         
               /* String host = "smtp.gmail.com";//host name
   String from = "xxxx@gmail.com";//sender id
   String to = "xxxxx@gmail.com";//reciever id
   String pass = "*******";//sender's password
   String fileAttachment = "E:\\Exaple.txt";//file name for attachment
   //system properties
   Properties prop = System.getProperties();
   // Setup mail server properties
   prop.put("mail.smtp.gmail", host);
   prop.put("mail.smtp.starttls.enable", "true");
   prop.put("mail.smtp.host", host);
   prop.put("mail.smtp.user", from);
   prop.put("mail.smtp.password", pass);
   prop.put("mail.smtp.port", "465");
   prop.put("mail.smtp.auth", "true");
   //session
   Session session = Session.getInstance(prop, null);
   // Define message
   MimeMessage message = new MimeMessage(session);
   message.setFrom(new InternetAddress(from));
   message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
   message.setSubject("subject");
   // create the message part
   MimeBodyPart messageBodyPart = new MimeBodyPart();
   //message body
   messageBodyPart.setText("Hi");
   Multipart multipart = new MimeMultipart();
   multipart.addBodyPart(messageBodyPart);
   //attachment
   messageBodyPart = new MimeBodyPart();
   DataSource source = new FileDataSource(fileAttachment);
   messageBodyPart.setDataHandler(new DataHandler(source));
   messageBodyPart.setFileName(fileAttachment);
   multipart.addBodyPart(messageBodyPart);
   message.setContent(multipart);
   //send message to reciever
   Transport transport = session.getTransport("smtp");
   transport.connect(host, from, pass);
   transport.sendMessage(message, message.getAllRecipients());
   transport.close();*/



Tuesday, 16 April 2013

Create Jasper Report


Step 1:
Create .jrxml file using Ireport Tool
File->new->file name
Step 2:
Get Table in control  and drag into details band and follow instructions.
















































































































Final Result:
Show in jasper viewer.


















Another way to call .jrxml file into java

Add jar



























 Create Java class and Refer the code

String qu="SELECT * from role";
Statement statement = (Statement) connection.createStatement();
ResultSet resultSet = (ResultSet) statement.executeQuery(qu);
jasperDesign = JRXmlLoader.load("F://project backup//Report5.jrxml");
jasperReport = JasperCompileManager.compileReport(jasperDesign);
jasperPrint = JasperFillManager.fillReport(jasperReport,parameters, new JRResultSetDataSource(resultSet));
JasperViewer.viewReport(jasperPrint, false);


Use resultset to show the result in Jasper viewer.

              

Friday, 5 April 2013

Add Event in Calender using JSP Page

Step 1:
          create jsp and

         <div id='calendar'></div>

Step 2:
    add js file into the JSP 
     for eg:


<link rel='stylesheet' type='text/css' href='fullcalendar/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='fullcalendar/fullcalendar.print.css' media='print' />
<script type='text/javascript' src='extensions/jquery-1.3.2.min.js'></script>

Step 3:
  Add .css in JSP



<style type='text/css'>

body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}

#loading {
position: absolute;
top: 5px;
right: 5px;
}

#calendar {
width: 900px;
margin: 0 auto;
}

</style>


Step 4:
   write code on script



<script type='text/javascript'>

$(document).ready(function() {


var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {

calendar.fullCalendar('unselect');
},
editable: true,


});


Step 5:

     Create servlet to getting event on table 
    or u direct Post the event on calender
    i am useint table for event

      write code on AJAX

$.ajax({ type: "Post", url: "Calender_Event",
data:{name:$("#Uname").val()},
cache:false,
success : function(data){

var objArray=JSON.parse(data);
 $.each(objArray, function(index,jsonObject){

   var subject = jsonObject.Description;  //the title of the event        
var dateStart = jsonObject.complDate;     // the day the event takes place
var events=new Array();  
event = new Object();    
event.title = subject;
event.start = dateStart;    // its a date string
//event.end = dateEnd;        // its a date string.
event.color = jsonObject.color;
event.allDay = false;
       event.url="Calender_Add_Report.jsp";
events.push(event);
$('#calendar').fullCalendar('addEventSource',events);

 });

  var altField = $( ".selector" ).datepicker( "option", "altField" );
 alert(altField);
}
});


Step 6:
Out Put  












Create dynamic jsp file and print this file


Step 1:
Simple Html File
add Button On Html File


 <input type="button"  onclick="a();" value="Demo Example ">






Step 2:
write code on script in  function a()

<script type="text/javascript">
    function a()
    {  
    var disp_setting="toolbar=no,location=no,directories=no,menubar=n0,";
    disp_setting+="scrollbars=yes,width=700, height=330,left=300,top=325";
    var rate_print=window.open("","",disp_setting);
    rate_print.document.open();
    rate_print.document.writeln('<html><head><title>Sample DEMO     </title>');
    rate_print.document.writeln('</head><body bgcolor="#b8f8f7"><center>');
    rate_print.document.writeln("<table align='center' cellspacing='0'
       border='1'     bordercolor='#000000'
       style='border-collapse:collapse' width='100%' id='viewparticipant'>");
    rate_print.document.writeln("<tr>");
    rate_print.document.writeln("<th class='tstyle' style='page-break-after:always'>S.NO</th>");
    rate_print.document.writeln("<th class='tstyle' style='page-break-after:always'>Vendor Name</th>");
    rate_print.document.writeln("<th class='tstyle' style='page-break-after:always'>Address</th>");
    rate_print.document.writeln("<th class='tstyle' style='page-break-after:always'>Quantity</th>");
    rate_print.document.writeln("<th class='tstyle' style='page-break-after:always'>Size</th>");
    rate_print.document.writeln("<th class='tstyle' style='page-break-after:always'>Rate</th>");
    rate_print.document.writeln("<th class='tstyle' style='page-break-after:always'>Date</th>");
    rate_print.document.writeln("</tr>");
    for(var i=0,j=1;i<100;i=i+1,j++)
    {
    rate_print.document.writeln("<tr>");
    rate_print.document.writeln("<td valign='center' align='center'> "+j+"</td>");
    rate_print.document.writeln("<td valign='center' align='left'>"+"Bharat"+" </td>");
    rate_print.document.writeln("<td valign='center' align='left'>"+"Shirur"+" </td>");
    rate_print.document.writeln("<td valign='center' align='right'>"+"24"+" </td>");
    rate_print.document.writeln("<td valign='center' align='right'>"+"22"+" </td>");
    rate_print.document.writeln("<td valign='center' align='right'>"+"32423423"+" </td>");
    rate_print.document.writeln("<td valign='center' align='center'>"+"19/10/1987"+" </td>");
    rate_print.document.writeln("</tr>");
    }/**end of the for loop*/
      rate_print.document.writeln("</table>");
    rate_print.document.writeln("<br>");
    rate_print.document.writeln("<input id='ok' type='button' value='Ok'
        class='blackbuttonlow'     tabindex='1' onclick='window.close()'> ");
    rate_print.document.writeln("&nbsp&nbsp&nbsp");
    rate_print.document.writeln("<input type='button'
        value='Print' tabindex='1'   onClick='this.style.visibility=\"hidden\"; window.print();'/>");
    rate_print.document.writeln('</center></body></html>');
    rate_print.document.close();
    rate_print.focus()
    }
 
    </script>

Step 3
Run Program (click on Button)



click on Print Button