Sponsered Links
Categories
Sponsered Links

User Login Page

 

This is a simple login page application using servlet. In this example we are using JDBC-ODBC Driver for databse connectivity. In the example you can see we are using doGet() method, which is used to send the web request in a query form, it process fast than doPost() method. The sendRedirect method is used to send one page to another page.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;


public class login extends HttpServlet
{
 
   Connection conn;
   Statement stmt;
   ResultSet rs;
   String s="";

     public void init()
     {
 try
  {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     conn=DriverManager.getConnection("Jdbc:Odbc:singh");
     s="Your information is connected ......";
         }catch(Exception e)
       {
         s="Exception 1....."+e.getMessage();
       }
   
      }
      public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException
      {
                    PrintWriter out = res.getWriter();
                    out.println(s);
                    String ss=req.getParameter("b1");

                      
                            try
                               {
                                 String ID=req.getParameter("t1");
                                 String pass=req.getParameter("t2");
                                 String ss1="select * from bank where ID='"+ID+"'";

                                 stmt=conn.createStatement();
                                 rs=stmt.executeQuery(ss1);

                                    if(rs.next())
                                    {
                                       
                                       
                                        if(rs.getString(2).equals(pass))
                                        {
                                             res.sendRedirect("/c1/login1.html");
                                        }
                                     }
                                    else
                                     {
                                         res.sendRedirect("/c1/login2.html");  
                                     }
                                   
                                  
                                   
                                  }
                                  catch(Exception e)
                                  {
                                     out.println("Unable To Show the info... . . ."+e.getMessage());
                                  }


                    
        }
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved