Servlet response.sendRedirect(url)不会更新浏览器中的URL

时间:2014-03-15 17:14:09

标签: jsp servlets redirect

尝试使用Servlet从一个JSP页面重定向到另一个JSP页面时遇到问题。将加载已请求的页面,但URL将保留在控制器URL上。

JSP调用:

    <a href="../MobileZuDesktopController" class="ui-btn">Desktop Version</a>

此JSP文件位于webapp / mobile / index.jsp下,而目标是/webapp/index.jsp。 在向Session添加标志后,我正在使用response.sendRedirect(“index.jsp”)来重定向请求。

    public class MobileZuDesktopController extends HttpServlet {
private static final long serialVersionUID = 1L;
private String url = "index.jsp";
private HttpSession session;



public MobileZuDesktopController() {
    super();

}
public void init(ServletConfig conf) throws ServletException  {
    super.init(conf);
}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    session = request.getSession();
    session.setAttribute("UseristMobile", 0);
    System.out.println(session.getAttribute("UseristMobile"));
    response.sendRedirect(url);

}

重定向后,CorrectPage“index.jsp”被加载,但浏览器的URL仍然是webapp / MobileZuDesktopController,并且在页面重新加载URL更新为webapp / index之后,前一页面的CSS仍处于活动状态.jsp并加载了正确的CSS。

我找不到这个设置的问题,根据我发现的所有资源,sendRedirect()函数应该具有所需的效果。我的代码有问题吗?

0 个答案:

没有答案
相关问题