Java 重定向后,Servlet名称仍在Url中(jQuery使用多页)
我已经找了好几天了。我使用的是jQuery(mobile)框架和多页index.jsp index.jspJava 重定向后,Servlet名称仍在Url中(jQuery使用多页),java,jquery,servlets,redirect,multipage,Java,Jquery,Servlets,Redirect,Multipage,我已经找了好几天了。我使用的是jQuery(mobile)框架和多页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">
//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>
....
<form action="DoLogin" method="POST">
...some inputs and formatting
<button class="ui-btn ui-btn-b" type="submit">Login</button>
</form>
}
当您未登录时,重定向到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项目。实际上是这个项目
解决了我的问题。我在表单中使用data ajax=“false”
@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;
}