Search code examples
javajqueryservletshttp-redirectmultipage

Servlet name still in Url after redirecting (jQuery using multipage)


I'm searching for days now. I'm using the jQuery (mobile) Framework and using a multipage index.jsp.

index.jsp

//Redirecting to login.jsp (not part of multipage) if user is not logged in. Checking Attribute in Bean.

<div data-role="page" id="page1">
    <jsp:include page="jsp/header.jsp">
        <jsp:param name="page" value="page1name" />
    </jsp:include>
    <jsp:include page="jsp/home.jsp" />
    <jsp:include page="jsp/footer.jsp" />
</div>

<div data-role="page" id="page2">
    <jsp:include page="jsp/header.jsp">
        <jsp:param name="page" value="page2name" />
    </jsp:include>
    <jsp:include page="jsp/profileView.jsp" />
    <jsp:include page="jsp/footer.jsp" />
</div>
....

login.jsp

<form action="DoLogin" method="POST">
...some inputs and formatting
<button class="ui-btn ui-btn-b" type="submit">Login</button>
</form>

DoLogin

@WebServlet(name = "DoLogin", urlPatterns = {"/DoLogin/*"})
public class DoLogin extends HttpServlet {
....
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

///Some code
if (checkPw is correct) {
                //setUserInBean
                //...
                response.sendRedirect("index.jsp");
                return;
            } else {
                response.sendRedirect("login.jsp?meldung=loginfalse");
                return;
}

}

Redirecting to login.jsp, when you are not logged in, works fine and login works fine, too, but just the redirect doesn't work as expected. I am redirected to index.jsp, but the url says www.app.com/DoLogin instead of www.app.com/index.jsp.

Even better would be, when I am redirecting to index.jsp that the url just says www.app.com/ instead of www.app.com/index.jsp because I have to call every site with an anchor and I cannot call sites when something is before the anchor for example "...com/index.jsp#page1". I need to call "...com/#page1".

Do I need to use javascript and have to replace sth or have to configure the web.xml? I also tried to use servlet, servlet-mapping, url-pattern etc. in web.xml, but didn't work, so I am still using @webservlet...

Btw, I am using a Maven project.


Solution

  • Actualy this jQuery mobile pages not loading correctly after servlet redirect

    solved my issue. I am using data-ajax="false" for the form