Guest User

Untitled

a guest
Dec 6th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import javax.servlet.*;
  4. import javax.servlet.http.*;
  5.  
  6. public class MyServlet extends HttpServlet {
  7.  
  8. public void doPost(HttpServletRequest req, HttpServletResponse res)
  9. throws ServletException, IOException {
  10. res.setContentType("text/html");
  11. PrintWriter out = res.getWriter();
  12.  
  13. String username = req.getParameter("username");
  14. String password = req.getParameter("password");
  15.  
  16. if (allowUser(username, password)) {
  17. out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
  18. out.println("<BODY>Your login and password are invalid.<BR>");
  19. out.println("</BODY></HTML>");
  20. }
  21. else {
  22. out.println("<HTML><HEAD><TITLE>Access Granted</TITLE></HEAD>");
  23. out.println("<BODY>Your login and password are valid.<BR>");
  24. out.println("</BODY></HTML>");
  25. HttpSession session = req.getSession();
  26. session.setAttribute("logon.isDone", username);
  27.  
  28. try {
  29. String target = (String) session.getAttribute("login.target");
  30. if (target != null) {
  31. res.sendRedirect(target);
  32. return;
  33. }
  34. }
  35. catch (Exception ignored) { }
  36.  
  37. //res.sendRedirect("/");
  38. }
  39. }
  40.  
  41. protected boolean allowUser(String username, String password) {
  42. return true;
  43. }
  44. }
Add Comment
Please, Sign In to add comment