| | |
URL in address bar,didnt change but the view is correct
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 0
I'm building small application, im kinda newbie in jsp..I use the MVC n servlets concepts..
My problem is after from servlets, the page i want to go (change to another place) cannot shown in the address bar correctly(the addressbar still showing the servlet page), but the view is exactly d same with the page i want to go..
I create a login page in file main.jsp, i send the data to ControlIndex servlet, n if login success go to mgmtActivity.jsp, all the error things while login i saved in the list errors.
This is my servlet code:
Can anyone help me with this problem? Thanks before..
My problem is after from servlets, the page i want to go (change to another place) cannot shown in the address bar correctly(the addressbar still showing the servlet page), but the view is exactly d same with the page i want to go..
I create a login page in file main.jsp, i send the data to ControlIndex servlet, n if login success go to mgmtActivity.jsp, all the error things while login i saved in the list errors.
This is my servlet code:
JSP Syntax (Toggle Plain Text)
public class ControlIndex extends HttpServlet { private List errors = new Vector(); private HttpSession session; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { session = request.getSession(); errors.clear(); boolean statusLogin = false; String aksi = request.getParameter("aksi"); if (aksi.equals("login")){ String username = request.getParameter("username"); String password = request.getParameter("password"); User user = null; // input validation if ((username == null) || !username.trim().matches("^[a-zA-Z]+$")){ errors.add("Username cannot contains white space or non alphabetic characters."); } // execute if (errors.size()==0){ user = User.getUser(username); if (user == null){ errors.add("Cannot find those username."); } else{ if (user.validatePassword(password)){ statusLogin = true; } else{ errors.add("Wrong password."); } } } if (statusLogin){ //set session session.setAttribute("user", user); RequestDispatcher view = request.getRequestDispatcher("mgmtActivity.jsp"); try{ view.forward(request, response); }catch(ServletException e){ e.printStackTrace(); } } }else if (aksi.equals("logout")){ //delete session session.setAttribute("user", null); } if (errors.size()!=0){ request.setAttribute("errors", errors); } RequestDispatcher view = request.getRequestDispatcher("main.jsp"); try{ view.forward(request, response); }catch(ServletException e){ e.printStackTrace(); } } }
![]() |
Other Threads in the JSP Forum
- Previous Thread: JSF HTTP 500 error
- Next Thread: Using Beans in jsp....PLEASE HELP ME STUCK BADLY From 9 days
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write





