重定向后 Servlet 名称仍在 Url 中(jQuery 使用多页)
Servlet name still in Url after redirecting (jQuery using multipage)
我已经找了好几天了。我正在使用 jQuery(移动) 框架并使用 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;
}
}
重定向到 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 并且必须更换某物或必须配置 web.xml?我也尝试在web.xml中使用servlet、servlet-mapping、url-pattern等,但没有用,所以我仍在使用@webservlet...
顺便说一句,我正在使用 Maven 项目。
其实这个
解决了我的问题。我正在使用 data-ajax="false" 作为表单
我已经找了好几天了。我正在使用 jQuery(移动) 框架并使用 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;
}
}
重定向到 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 并且必须更换某物或必须配置 web.xml?我也尝试在web.xml中使用servlet、servlet-mapping、url-pattern等,但没有用,所以我仍在使用@webservlet...
顺便说一句,我正在使用 Maven 项目。
其实这个
解决了我的问题。我正在使用 data-ajax="false" 作为表单