Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


puvi
servlet
0 Answer(s)      2 years and 5 months ago
Posted in : JSP-Servlet


package com.ilp.tsi.um.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ilp.tsi.um.constant.BankConstant;

import com.ilp.tsi.um.dao.BankDao;
import com.ilp.tsi.um.bean.BankBean;
import com.ilp.tsi.um.service.BankService;

/**
 * Servlet implementation class AdminServlet
 */
public class BankServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    Connection conn;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public BankServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        try
        {
            conn=BankDao.createconnection();
        }
        catch(Exception e)
        {
            e.printStackTrace();

        }
        BankService loginService = new BankService();
        BankBean loginBean = new BankBean();
        loginBean.setUsername(request.getParameter("username"));
        loginBean.setPassword(request.getParameter("password"));
        boolean check = false;
        try
        {
            check = loginService.authenticate(loginBean,conn);
            conn.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }

        if(check){
            RequestDispatcher rd=request.getRequestDispatcher("customerinfo.jsp");
            rd.forward(request,response);
        }
        else{
            request.setAttribute("Message",BankConstant.MESSAGE);
            RequestDispatcher rd=request.getRequestDispatcher("failed.jsp");
            rd.forward(request,response);
        }//end else



    }

}

//2.servlet

package com.ilp.tsi.um.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.sql.*;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ilp.tsi.um.dao.BankDao;


public class CustDet extends HttpServlet
              //perform operation to get retailer information
{
    private static final long serialVersionUID = 1L;
    Connection connection = null;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CustDet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

            response.setContentType("text/html");
            PrintWriter pw = response.getWriter();  
            //send response to browser
            String acc_num=request.getParameter("acc");
            String name=request.getParameter("name");
            String addr=request.getParameter("address");
            String ph=request.getParameter("phno");
            int n;

             try {
                 Class.forName("oracle.jdbc.driver.OracleDriver");
                 //driver definition
                 Connection con=BankDao.createconnection();
                 //establishing database connection
                 Statement stmt= con.createStatement();
                 n=stmt.executeUpdate("update customer set acc='"+acc_num+"',name='"+name+"',address='"+addr+"',phoneno='"+ph+"' where acc='"+acc_num+"'");

             }
             catch (ClassNotFoundException ce) {
                 ce.printStackTrace();
             }//end catch
             catch(SQLException e)
             {
            e.printStackTrace();
             }//end catch
             RequestDispatcher rd = request.getRequestDispatcher("update1.jsp"); 
             rd.forward(request,response);  
               }
            }

//3.servlet


package com.ilp.tsi.um.servlet;


import java.io.IOException;

import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ilp.tsi.um.dao.BankDao;


public class CustomerDetail extends HttpServlet {
                 //update retailer details
    private static final long serialVersionUID = 1L;
    Connection connection = null;



    /**
     * @see HttpServlet#HttpServlet()
     */
    public CustomerDetail() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
            response.setContentType("text/html");

            //send response to browser
            String s=request.getParameter("acc");

             try {



            Connection con=BankDao.createconnection();
            //establishing database connection
            Statement stmt= con.createStatement();
            ResultSet rs= stmt.executeQuery("select * from customer where acc='"+s+"'");
                //iterating the resultset for data from database
                while(rs.next())
                {
                    request.setAttribute("acc",rs.getString(1));
                    request.setAttribute("name",rs.getString(2));
                    request.setAttribute("address",rs.getString(3));
                    request.setAttribute("phno",rs.getString(4));
                    RequestDispatcher rd = request.getRequestDispatcher("updateinfo.jsp"); 
                    rd.forward(request,response); 
                }


        }

        catch(SQLException e)
        {
            e.printStackTrace();

        }//end catch


    }
            }

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Servlet
Servlet  What is Servlet
Servlet
Servlet  how to navigate one servlet page to another servlet page
Advertisements
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  How many times the servlet is accessed
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  i want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
Servlet
override Service method in the servlet when you extend GenericServlet to create servlet as it is mandatory to override it. But, when you extend HttpServlet to create a servlet then you can't override service method as there is a need to override
servlet
of the Servlet API. It contains the classes necessary for a standard, protocol-independent servlet. Every servlet must implement the Servlet interface in one
servlet
servlet  can i stoar record in variable which selected from table in servlet
servlet
servlet  dear sir servlet and html not run on eclips plz help me
servlet
servlet  how to create a login form using servlet using submit,edit delete button
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
Servlet
Servlet  What must be implemented by all Servlets?    The Servlet Interface must be implemented by all servlets
Servlet
Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import
servlet
servlet  I want the full coding for uploading a file in local drive D usin jsp,java class and servlet... help me thanks in advance....   ... and servlet please and thanks in advance
Servlet
Servlet  Can a user defined function be included in a servlet? I need information regarding servlet syntax and not JSP.   Yes, you can create user defined function in Servlets. Have a look at the following link: http
servlet
servlet  how to read a file from different folder using filereader in servlet   Hello Friend, Please visit the following link: http://www.roseindia.net/servlets/servlet-read-file.shtml Here you will get an useful
servlet
servlet  i want to use servlet application on my web page then what should i do. I have already webspace.   Hi Friend, Please visit the following link: Servlet Tutorials Thanks
Servlet
Servlet   Why is Servlet so popular?   Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web
Servlet
Servlet  Hi, Can any one please expalin me below topics SERVLET ENGINE 2.WHY SUPER.INIT(); Thanks alot in advance!! Regards: Akash
servlet
servlet  I want a fully readymade project on online voting system with code in java servlet and database backend as msaccess.can u plz send me as soon as possible
servlet
servlet  plz can anyone give me the link of javax library jar file. i badly need that. thanks in advance   Please visit the following link: Download Servlet API
servlet
servlet   Dear Deepak, is it compulsary to write the sevice() becoz i ve seen some example which does not ve sevice()..is it tue? plz replay me with thanks praveen
Servlet
the same error <web-app> <servlet> <servlet-name>InsertServlet</servlet-name> <servlet-class>InsertServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>
SERVLET
to the servlet and if the user id is correct then a new page will be displayed with his... pass to the servlet and all the fields brlongs to that id will be appear... will be done by using jsp and servlet... Plz help me,im really tensed...........  
servlet
servlet file which prints out the user's inputs. I need to use the post method to pass the data from html to the java servlet and also use both doGet and doPost methods in the servlet. I think, but unfortunately I have a terrible teacher
servlet
servlet  hi sir,this is ashok.i installed tomcat 6.0 and jdk-150.i checked the server it's working but when execute servlet program for the .class file it shows the errors javax.servlet is not exist.what can i do,please tell me
Advertisements
 

 

 

DMCA.com