Guest User

Untitled

a guest
Oct 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. protected void processRequest(HttpServletRequest request,
  2. HttpServletResponse response) throws ServletException, IOException {
  3. String username = request.getParameter("username");
  4. String password = request.getParameter("password");
  5.  
  6. switch(username) {
  7. case "client1":
  8. if(PASSWORD.equals(password)) {
  9. request.getSession(true).setAttribute("username", username);
  10. response.sendRedirect("app1/apk-1-index.html");
  11. }
  12. break;
  13.  
  14. case "client2":
  15. if(PASSWORD.equals(password)) {
  16. request.getSession(true).setAttribute("username", username);
  17. response.sendRedirect("app2/apk-2-index.html");
  18. }
  19. break;
  20.  
  21. case "client3":
  22. if(PASSWORD.equals(password)) {
  23. request.getSession(true).setAttribute("username", username);
  24. response.sendRedirect("app3/apk-3-index.html");
  25. }
  26. break;
  27.  
  28. case "client4":
  29. if(PASSWORD.equals(password)) {
  30. request.getSession(true).setAttribute("username", username);
  31. response.sendRedirect("app4/apk-4-index.html");
  32. }
  33. break;
  34. case "client5":
  35. if(PASSWORD.equals(password)) {
  36. request.getSession(true).setAttribute("username", username);
  37. response.sendRedirect("app5/apk-5-index.html");
  38. }
  39. break;
  40. case "client6":
  41. if(PASSWORD.equals(password)) {
  42. request.getSession(true).setAttribute("username", username);
  43. response.sendRedirect("app5/apk-5-index.html");
  44. }
  45. break;
  46. default:
  47. response.sendRedirect("/Test2/index.jsp");
  48. }
  49. }
  50.  
  51. case <THIS PART IS DIFFERENT>:
  52. if(PASSWORD.equals(password)) {
  53. request.getSession(true).setAttribute("username", username);
  54. response.sendRedirect(<THIS PART IS DIFFERENT>);
  55. }
  56.  
  57. Map<String, String> redirects = new HashMap<>();
  58. redirects.put("client1", "app1/apk-1-index.html");
  59. redirects.put("client2", "app2/apk-2-index.html");
  60. redirects.put("client3", "app3/apk-3-index.html");
  61. ....
  62.  
  63. String redirect = redirects.get(username);
  64. if (redirect == null) {
  65. response.sendRedirect("/Test2/index.jsp");
  66. return;
  67. }
  68.  
  69. if (PASSWORD.equals(password)) {
  70. request.getSession(true).setAttribute("username", username);
  71. response.sendRedirect(redirect);
  72. }
Add Comment
Please, Sign In to add comment