Reputation: 599
My web app directory structure is
myApp
-src
- filtersPackage(all my filters lie in this package)
- servletsPackage(all my controllers and models lie in this package)
- web-content
- web
- views(all my jsp files lie in this dir)
- js(all my javascript files lie in this dir)
In login.jsp, user clicks on FB login button, inside js/FBAUth.js I collect login details and I send it to my auth.do servlet using jquery ajax POST method.
The SessionFilter allows the request to go to AuthServlet's doPost method. In AuthServlet If the credentials are correct then do the following
url = "dashboard.jsp"
request.getSession().setAttribute("uid", id);
view = request.getRequestDispatcher(url);
view.forward(request, response);
return;
I have seen in debug mode that these lines execute but my browser is still stuck on login page. The values for view.requestURI -> /myApp/web/views/dashboard.jsp and view.servletPath -> /web/views/dashboardTmp.jsp. I also tried response.sendRedirect(url), but still the browser is stuck on login page. Nothing executes after these lines.
In web.xml, my auth servlet is mapped as follows
<servlet>
<servlet-name>Auth</servlet-name>
<servlet-class>servletsPackage.AuthServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Auth</servlet-name>
<url-pattern>/web/views/auth.do</url-pattern>
</servlet-mapping>
I also tried calling doGet inside doPost, and executed this code in doGet, but all in vain. What am I missing here ?
Upvotes: 0
Views: 3720
Reputation: 3183
Try to return something from your servlet (write in response writer), retrieve that as ajax response, depending upon that, do a window.location.href ="YOUR URL";
Upvotes: 0
Reputation: 1269
This approach seems to be a bit flawed. Your forward is not working because you are using AJAX to post data. You would need to use javascript or rather jquery to handle the redirection.
Check if your jquery AJAX function's callback method is working. print out the responseText using alert(responseText);
Check this link for more information about your problem. And check the first answer. It provides a solution for this problem.
Upvotes: 1