package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.LoginBean;
import doa.UserDOA;
/**
* Servlet implementation class LoginServlet
*/
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public LoginServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stubt
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
LoginBean lbean = new LoginBean();
String username = request.getParameter("username");
String password = request.getParameter("password");
lbean.setUsername(username);
lbean.setPassword(password);
lbean = UserDOA.login(lbean);
if(lbean.isValid()){
HttpSession session = request.getSession(true);
session.setAttribute("currentSessionUser",lbean);
response.sendRedirect("RegisteredUser.jsp"); //logged-in page
}else{
//out.println("<h1> Username and Password Not Matched </h1>");
response.sendRedirect("InvalidUser.jsp"); //error page
}
}
}
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.LoginBean;
import doa.UserDOA;
/**
* Servlet implementation class LoginServlet
*/
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public LoginServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stubt
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
LoginBean lbean = new LoginBean();
String username = request.getParameter("username");
String password = request.getParameter("password");
lbean.setUsername(username);
lbean.setPassword(password);
lbean = UserDOA.login(lbean);
if(lbean.isValid()){
HttpSession session = request.getSession(true);
session.setAttribute("currentSessionUser",lbean);
response.sendRedirect("RegisteredUser.jsp"); //logged-in page
}else{
//out.println("<h1> Username and Password Not Matched </h1>");
response.sendRedirect("InvalidUser.jsp"); //error page
}
}
}
No comments:
Post a Comment