Advertisement
Guest User

Untitled

a guest
Jul 13th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package ro.teamnet.zth.web;
  2.  
  3. import javax.servlet.RequestDispatcher;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.http.HttpServlet;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. import java.io.IOException;
  9.  
  10. /**
  11. * Created by user on 7/14/2016.
  12. */
  13. public class HttpSessionZTH extends HttpServlet {
  14. @Override
  15. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  16. String userName = "";
  17. String password = "";
  18.  
  19. // Set the response type
  20. resp.setContentType("text/html");
  21.  
  22. // Obtain the user from the request instance
  23. userName = req.getParameter("username");
  24. password = req.getParameter("password");
  25.  
  26. if(userName.equals("admin") && password.equals("admin")){
  27. resp.getWriter().write("Welcome back!<br>"+"Username:" +userName+ " " + req.getRequestedSessionId());
  28. }
  29. else{
  30. req.getSession().setAttribute("username", userName);
  31. req.getSession().setAttribute("session", req.getSession());
  32. RequestDispatcher requestDispatcher = req.getRequestDispatcher("views/loginFail.jsp");
  33. requestDispatcher.forward(req, resp);
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement