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);
}
}
}