重定向后的Servlet名称仍在Url中(使用多页的jQuery)



我已经找了好几天了。我正在使用jQuery(移动)框架,并使用多页 index.jsp。

<<p> index . jsp/strong>
//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;
}

}

当您没有登录时,重定向到login.jsp可以正常工作,登录也可以正常工作,但只是重定向不能像预期的那样工作。我被重定向到index.jsp,但是url显示的是www.app.com/DoLogin而不是www.app.com/index.jsp。

更好的是,当我重定向到index.jsp的url只是说www.app.com/而不是www.app.com/index.jsp,因为我必须调用每个网站与锚,我不能调用网站时,有些东西是锚之前,例如"…com/index.jsp#page1"。我需要调用"…com/#page1"

我是否需要使用javascript并且必须替换sth或必须配置web.xml?我还尝试在web.xml中使用servlet, servlet映射,url模式等,但没有工作,所以我仍然使用@webservlet…

顺便说一句,我使用的是Maven项目

实际上这个jQuery移动页面在servlet重定向后没有正确加载

解决了我的问题。我使用data-ajax="false"的形式

最新更新