Heading

Wednesday, March 5, 2014

Web Application in Java with JDBC, Servlets, JSp and MYSQL DataBase-14

 Login. java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author SDSTAFF
 */
   import java.io.*;
   import java.sql.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
   public class Login extends HttpServlet {
    String username="";
    String password="";
    String mail="";
    Connection con=null;
    Statement st=null;
    Statement st1=null;
    ResultSet rs=null;
    ResultSet rs1=null;
    RequestDispatcher rd=null;
    HttpSession sn=null;
    PrintWriter out=null;
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException {
        username = req.getParameter("user");
        password = req.getParameter("pass");
        System.out.println("username");
        HttpSession sn = req.getSession(true);
        sn.setAttribute("eid",username);
        res.setContentType("text/html");
        out = res.getWriter();
        sn = req.getSession(true);
        sn.setAttribute("username",username);
        RequestDispatcher rd;
      
                try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","password");
            st = con.createStatement();
            rs = st.executeQuery("select * from userlogin where userid='"+username+"' && passid='"+password+"'");
        if(rs.next())
            {
               
                st1=con.createStatement();
                rs1=st1.executeQuery("select email from userlogin where userid='"+username+"'");
                while(rs1.next())
                {
                mail=rs1.getString("email");
                sn = req.getSession(true);
                sn.setAttribute("emai",mail);
                System.out.println(mail);
                }
                rd=req.getRequestDispatcher("User_Home.jsp");
            }
            else {
                rd=req.getRequestDispatcher("Login_Fail.jsp");
                //out.println("welcome");
            }
            rd.forward(req,res);
        } catch(Exception e2) {
            //System.out.println("Exception : "+e2.toString());
              out.println(e2);
        }
    }
}

1 comment:

  1. In this article, we will give you the fundamental data about meta information, alleged meta data in Magento 2.
    magento tutorial
    magento breadcrumb
    magento 2 extension installation guide

    ReplyDelete