Maximilian
Lifer
So im trying to uncouple my rather tightly coupled webpage by using a FrontController servlet that will route all requests to the other servlets, it comtains code like:
And so on... They both go to the same servlet right now, thats okay though. Here is the LoginPageServlet code that the FrontController sends these particular requests to:
Unfortunately this redirects to the URL: "http://localhost:8080/fitness_tracker_servlet_maven/FrontController/desktopLogin.html"
When what I want it to do is redirect to:
"http://localhost:8080/fitness_tracker_servlet_maven/desktopLogin.html"
I assume this is because I am using RequestDispatcher and I theres something im missing about how it all works. I can fix it by doing this:
But it would still be good to know why that happens with "FrontController" being part of the URL response.
Code:
if (currentRequestString.equals(GlobalValues.getDesktopLoginPage()))
{
System.out.println("Desktop login path");
rd = request.getRequestDispatcher("/"+"LoginPageServlet");
rd.forward(request, response);
}
else if (currentRequestString.equals(GlobalValues.getMobileLoginPage()))
{
System.out.println("Mobile login path");
rd = request.getRequestDispatcher("/"+"LoginPageServlet");
rd.forward(request, response);
}
And so on... They both go to the same servlet right now, thats okay though. Here is the LoginPageServlet code that the FrontController sends these particular requests to:
Code:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
System.out.println("LoginPageServlet executing");
HttpSession session = request.getSession(false);
if(session == null) //path for invalid session
{
response.sendRedirect("desktopLogin.html");
}
else if(session.getAttribute("username") == null) //path for invalid username
{
//no username in session
//user probably hasn't logged in properly
response.setContentType("text/html");
response.sendRedirect("desktopLogin.html");
}
else //path for valid session
{
response.sendRedirect("alreadyLoggedIn.html");
}
}
Unfortunately this redirects to the URL: "http://localhost:8080/fitness_tracker_servlet_maven/FrontController/desktopLogin.html"
When what I want it to do is redirect to:
"http://localhost:8080/fitness_tracker_servlet_maven/desktopLogin.html"
I assume this is because I am using RequestDispatcher and I theres something im missing about how it all works. I can fix it by doing this:
Code:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
System.out.println("LoginPageServlet executing");
HttpSession session = request.getSession(false);
if(session == null) //path for invalid session
{
response.sendRedirect[B]("/fitness_tracker_servlet_maven/desktopLogin.html")[/B];
}
else if(session.getAttribute("username") == null) //path for invalid username
{
//no username in session
//user probably hasn't logged in properly
response.setContentType("text/html");
response.sendRedirect[B]("/fitness_tracker_servlet_maven/desktopLogin.html")[/B];
}
else //path for valid session
{
response.sendRedirect("alreadyLoggedIn.html");
}
}
But it would still be good to know why that happens with "FrontController" being part of the URL response.