Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void processRequest(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- String username = request.getParameter("username");
- String password = request.getParameter("password");
- switch(username) {
- case "client1":
- if(PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect("app1/apk-1-index.html");
- }
- break;
- case "client2":
- if(PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect("app2/apk-2-index.html");
- }
- break;
- case "client3":
- if(PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect("app3/apk-3-index.html");
- }
- break;
- case "client4":
- if(PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect("app4/apk-4-index.html");
- }
- break;
- case "client5":
- if(PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect("app5/apk-5-index.html");
- }
- break;
- case "client6":
- if(PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect("app5/apk-5-index.html");
- }
- break;
- default:
- response.sendRedirect("/Test2/index.jsp");
- }
- }
- case <THIS PART IS DIFFERENT>:
- if(PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect(<THIS PART IS DIFFERENT>);
- }
- Map<String, String> redirects = new HashMap<>();
- redirects.put("client1", "app1/apk-1-index.html");
- redirects.put("client2", "app2/apk-2-index.html");
- redirects.put("client3", "app3/apk-3-index.html");
- ....
- String redirect = redirects.get(username);
- if (redirect == null) {
- response.sendRedirect("/Test2/index.jsp");
- return;
- }
- if (PASSWORD.equals(password)) {
- request.getSession(true).setAttribute("username", username);
- response.sendRedirect(redirect);
- }
Add Comment
Please, Sign In to add comment