My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
servletexample
Posted Date:
Total Responses: 0
Posted By: Mahesh Member Level: Platinum Points/Cash: 3
|
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; import java.sql.*;
public class NetServ extends HttpServlet { Connection con2; Statement stmt11,stmt22,stmt33; ResultSet rsninq,rs2; int greenFlag=1; public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException { doGet(req,res); }
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException { int i=0; String st[]=new String[20];
PrintWriter out= res.getWriter(); res.setContentType("text/html"); Enumeration enum=req.getParameterNames();//receiving all the parameters from spageacc.java
//this while loop is chakinf whether any of the field on the page is left empty by the user // if it is the case green is set to 0.Oterwise the greenFlag is 1 by default while(enum.hasMoreElements()) { st[i]= (String)enum.nextElement(); // out.println(st[i]+" "+req.getParameter(st[i]));
if( ( req.getParameter(st[i])).equals("") ) { greenFlag=0; } i++; }
//if greenflag is 0 , generates error message if(greenFlag==0) { out.println(" Click the"); out.println(" "); out.println(" Back Information is incomplete. button to try previous page . "); greenFlag=1; }
else { try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con2=DriverManager.getConnection("jdbc:odbc:usersource","","");
stmt11=con2.createStatement(); stmt22=con2.createStatement(); stmt33=con2.createStatement(); String dt=req.getParameter("month")+"-"+req.getParameter("date")+"-"+req.getParameter("year"); System.out.println(dt);
// Stores the information in network Table stmt11.executeUpdate("insert into network values("+Integer.parseInt(req.getParameter("number")) + ",'"+req.getParameter("Cables")+"','"+req.getParameter("patchview")+"','"+req.getParameter("misc")+ "'," + Integer.parseInt(req.getParameter("code"))+",'" +dt+"',"+Integer.parseInt(req.getParameter("code"))+",'"+dt+"')");
rsninq=stmt33.executeQuery("select * from bgroup where bgroup_name="+"'"+req.getParameter("Business")+"'"); rsninq.next();
//Stores the information in inquiry table
stmt22.executeUpdate("insert into inquiry values("+Integer.parseInt(req.getParameter("number")) + ",'"+dt+"','"+req.getParameter("client1")+"','"+req.getParameter("contact")+"','"+req.getParameter("desig")+"','"+req.getParameter("address")+"','"+req.getParameter("tel")+"','"+req.getParameter("fax")+"','"+req.getParameter("email")+"',"+rsninq.getInt("bgroup_id")+","+Integer.parseInt(req.getParameter("code"))+","+Integer.parseInt(req.getParameter("code"))+",'"+dt+"',"+Integer.parseInt(req.getParameter("code"))+",'"+dt+ "')" );
//Fallowing code displays the second page again so that the salesperson should be able to enter the information about another //customer.if you remember , we had a big discussion on this issue.Previously i kept one button to go to back page and //you wanted to display this page automatically ,immediately after submitting the last form.
//this code fragment of the servlet is sending all those html instruction to the client side which are required to generate the // second form i.e the form which is generated by after the execution of fpage.java Remember ....... first form is the form where we enter user id and password .for this form we have MIS.html int empId,inqnm,tempinqnm; double psWord=0.0; String reg,bra; i=0; Connection ncon; Statement stmt1,stmt2,stmt3,stmt4; ResultSet nrs1,rsBranch,rsRegion,rsInq; String str[]=new String[2];
empId=Integer.parseInt(req.getParameter("code")); Double in=new Double(req.getParameter("password")); psWord=in.doubleValue();//new
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); ncon=DriverManager.getConnection("jdbc:odbc:usersource","",""); stmt1=ncon.createStatement(); nrs1=stmt1.executeQuery("select * from emp where emp_id = "+empId+"and password="+psWord);
nrs1.next(); stmt2=ncon.createStatement(); stmt3=ncon.createStatement(); stmt4=ncon.createStatement();
rsBranch=stmt2.executeQuery("select * from branch where branch_id = "+nrs1.getInt("branch_id"));
rsRegion=stmt3.executeQuery("select * from region where region_id = "+nrs1.getInt("region_id"));
rsInq=stmt4.executeQuery("select * from inqtrack");
rsBranch.next(); rsRegion.next(); rsInq.next();
inqnm=rsInq.getInt("inquirynm");
tempinqnm=inqnm+1; stmt4.executeUpdate("update inqtrack set inquirynm="+tempinqnm);
bra=rsBranch.getString("branch_name"); reg=rsRegion.getString("region_name");
out.println(""); out.println(""); out.println(""+"Nelito Systems Limited - MIS"+""); out.println(""); out.println(""); out.println(""); out.println(" "); out.println(""); out.println(" | "); out.println(" | "); out.println(" "); out.println(""); out.println(" | "); out.println(""); out.println(""); out.println(" | "); out.println(" | "); out.println(" | "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(""); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" | "); out.println(" "); out.println(" "); out.println(" "); out.println(" ");
} //End try
catch(SQLException e) { out.println("sdfsdfsdfsdfsdfsdfsdfsdfsdfsdsdfsdfs"); e.printStackTrace(); System.out.println("sql Error Error Error "); } catch(NumberFormatException e) { System.out.println("Number Error Error Error "); e.printStackTrace();
} catch(Exception e) { out.println("sdfsdfsdfsdfsdfsdfsdfsdfsdfsdsdfsdfs"); System.out.println("General Error Error Error "); } }//end Else
}//End Of get Method
}//End of servlet
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|