Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*UserModel*/
- public class User(){
- private String username;
- private String password;
- private String role;
- public User(){
- }
- /*Getter & setter*/
- public String getUsername(){return this.username;}
- public String setUsername(String username){this.username=username;}
- public String getPassword(){return this.password;}
- public String setPassword(String password){this.password=password;}
- public String getRole(){return this.role;}
- public String setRole(String role){this.role=role;}
- }
- /*Servlet demo*/
- /**
- * Servlet implementation class ProcessLogin
- */
- @WebServlet("/ProcessLogin")
- public class ProcessLoginaa extends HttpServlet {
- private static final long serialVersionUID = 1L;
- /**
- * @see HttpServlet#HttpServlet()
- */
- public ProcessLoginaa() {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String username=request.getParameter("username");
- String password=request.getParameter("password");
- /*Các pt để lấy CSDL*/
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection connection =DriverManager.getConnection(url+database,user,password);
- }catch(Exception e){
- }
- Statement statement = connection.createStatement() ;
- ResultSet rs=
- statement.executeQuery("select * from user where username='"+username'"+" password='"+password+"') ;
- User user=null;
- while(rs.next()){
- user=new User();
- user.setUsername(rs.getString(1));
- user.setRole(rs.getString(3));
- }
- HttpSession session = request.getSession();
- session.setAttribute("user", user);
- if(user.getRole()=='Admin'){
- request.getRequestDispatcher("adminpage.jsp").forward(request, response);
- }else{
- request.getRequestDispatcher("adminpage.jsp").forward(request, response);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement