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

标签 java jquery servlets redirect multipage

我已经找了好几天了。我正在使用jQuery(移动)框架并使用多页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>
....

登录.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,但网址显示www.app.com/DoLogin,而不是www.app.com/index.jsp。

更好的是,当我重定向到 index.jsp 时,该 url 只显示 www.app.com/而不是 www.app.com/index.jsp,因为我必须使用 anchor 调用每个站点,并且我当 anchor 之前有某些内容时,无法调用站点,例如“...com/index.jsp#page1”。我需要调用“...com/#page1”。

我是否需要使用 javascript 并必须替换某项或必须配置 web.xml?我还尝试在 web.xml 中使用 servlet、servlet-mapping、url-pattern 等,但没有成功,所以我仍在使用 @webservlet...

顺便说一句,我正在使用 Maven 项目。

最佳答案

其实这个jQuery mobile pages not loading correctly after servlet redirect

解决了我的问题。我正在使用 data-ajax="false"作为表单

关于java - 重定向后 Servlet 名称仍在 Url 中(使用多页的 jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33192108/

相关文章:

tomcat - Websphere 将错误附加到响应

java - Java HttpSession ID 对 FreeMarker 模板可见吗?

java - 从java中的泛型方法调用非泛型方法

javascript - MDL卡片高度定制

java - 当从 fragment 返回时,不会调用主 Activity 的 OnResume()

javascript - 在包含的 html 文件上定位图像

javascript - jquery验证器错误位置

tomcat - 在两个网络应用程序之间共享 session ID/登录信息

java - 使用 Arraylist 将其部分数据显示到 Android setMultiChoiceItems(Alert Dialog)

java - 无法将 NULL 插入列