Guest User

Untitled

a guest
Jun 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  7. <title>Login</title>
  8. </head>
  9. <body>
  10.  
  11. <form action="richiestaLogin" method="post">
  12. <div>Nome: <input type="text" name="username"/></div>
  13. <div>Password: <input type="password" name="password"/></div>
  14. <div><font color="red">${ errorLogin }</font></div>
  15. <div><input type="submit" name="submit" value="Invia"/></div>
  16. </form>
  17.  
  18. </body>
  19. </html>
  20.  
  21. package it.uniroma3.siw.controller;
  22.  
  23. import java.io.IOException;
  24.  
  25. import javax.servlet.ServletException;
  26. import javax.servlet.annotation.WebServlet;
  27. import javax.servlet.http.HttpServlet;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30. import javax.servlet.http.HttpSession;
  31.  
  32. @WebServlet("/richiestaLogin")
  33. public class LoginController extends HttpServlet {
  34. private static final long serialVersionUID = 1L;
  35.  
  36. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  37. throws ServletException, IOException {
  38.  
  39. HttpSession session = request.getSession();
  40.  
  41. String username = request.getParameter("username");
  42. String password = request.getParameter("password");
  43.  
  44. if (username.equals("admin") && password.equals("admin")) {
  45. session.setAttribute("username", username);
  46.  
  47. response.sendRedirect("pannelloControllo.jsp");
  48. }
  49. else {
  50. session.setAttribute("errorLogin", "Accesso non consentito.");
  51.  
  52. response.sendRedirect("login.jsp");
  53. }
  54.  
  55. }
  56.  
  57. }
Add Comment
Please, Sign In to add comment