Make a Login Page Using JSP(project:1) - NESTED CODE || TECH FLOAT

Breaking

Post Top Ad

Post Top Ad

Wednesday, 7 November 2012

Make a Login Page Using JSP(project:1)

Now we are in the second important step of our small project. Now we will make here the page for login.
The GUI interface (i.e. the user can see) will be like


So the HTML code to make this page is like ::

<%--
    Document   : login
    Created on : 2 Nov, 2012, 9:55:43 PM
    Author     : NESTED CODE
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login Page</title>
    </head>
    <body>
        <center><h1> <b><u>Login Here</u></b></h1><hr>
            <form action="l1.jsp">
                <br><b>Login ID<input type="text" name="id"></b>
                <br><b>Password<input type="password" name="password"></b><br>
                    <input type="submit" value="Login">
            </form>
            <br><hr>
                ** New User? <a href="register.jsp">Register Here</a>
                <hr>
    </center>
    </body>
</html>


Now we have to make this "l1.jsp" page. The code for this page ::

<%--
    Document   : jdbcjsp1
    Created on : 2 Nov, 2012, 5:45:34 PM
    Author     : NESTEDCODE TEAM
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <center>
        <h1>Wrong info || login failed</h1>
        <%@ page language="java" %>
        <%@ page import="java.sql.*" %>
         <%@ page import="java.sql.DriverManager.*" %>
       
        <%
        int flag=0;
        String m=null, mn=null;
        String s=request.getParameter("id");
        String s1=request.getParameter("password");
        PreparedStatement ps=null;
        Connection con= null;
        ResultSet rs= null;
       Class.forName("oracle.jdbc.driver.OracleDriver");
        con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","summer3");
      
         Statement st=con.createStatement();
       
           rs=st.executeQuery("select password from register where id='"+ s+"' ");
        
    
           while(rs.next())
               {
              
                  if(s1.equals(rs.getString(1)))
               {
                  flag=1;
                   break;
               }
           }
           if(flag==1)
               {
                RequestDispatcher rd=request.getRequestDispatcher("welcome.jsp");
              rd.forward(request,response);
           }
           else
               {
               out.println("wrong password");
              
           }
        %>
        <a href="login.jsp">User Login</a>
        </center>
    </body>
</html>


If the login process is correct then the page will redirect to "welcome.jsp" page where the user can check his murks(project purpose it is created) and then it will be like ::

about this "welcome.jsp" we will discus later.
If login process is failed then the page will stay at it's same condition and will give the user that it is a wrong process. Then the page will be like


So in the next blog we will discus how this welcome.jsp is created. And how the user can see his result. Thank You.

Previous Lesson                                                                                                  Next Lesson

No comments:

Post a Comment

Post Bottom Ad