package fastlearn;
import java.io.*;
import java.util.*;
import java.net.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author RITU
*/
public class login extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String eml=request.getParameter("fclognm");
String p=request.getParameter("fcpwd");
String user=request.getParameter("fcuser");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbcdbc:dbfastl earn");
PreparedStatement ps=con.prepareStatement("Select * from LogDetails where User_email='"+eml+"' and User_pwd='"+p+"'and User_Access='"+user+"'");
ResultSet rs=ps.executeQuery();
int count=0;
while(true){
if(rs.next()){
if(user.equals("admin")) {
RequestDispatcher dr=request.getRequestDispatcher("Admnstr.html");
dr.forward(request, response);
HttpSession session=request.getSession(true);
session.setAttribute("usr", user);
session.setAttribute("eml", eml);
}
else if(user.equals("fac")) {
RequestDispatcher dr=request.getRequestDispatcher("Faculty.jsp");
dr.forward(request, response);
HttpSession session=request.getSession(true);
session.setAttribute("usr", user);
session.setAttribute("eml", eml);
}
else if(user.equals("stud")){
RequestDispatcher dr=request.getRequestDispatcher("Student.jsp");
dr.forward(request, response);
HttpSession session=request.getSession(true);
session.setAttribute("usr", user);
session.setAttribute("eml", eml);
}
}
else {
RequestDispatcher dr=request.getRequestDispatcher("login.jsp");
dr.forward(request, response);
count++;
}
con.close();
// if(count>3){
// session.invalidate();
// out.println("<br>Sorry!! Your Account has been blocked!");
}
}
catch(Exception e){
out.println(e);
}
finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request
servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}
I want to start the session once the user successfully logged in, bt its showing null wen, on the user's page, I m printing out- session.getAttribute("eml"); I want to print out the login name instead.
Where I am goin wrong??
Is there any other way to start a session to get the result??