我已经找了好几天了。我正在使用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/