JSP重定向不起作用



我正在使用以下servlet代码发送特定URL的响应。

public class CasRedirectServlet extends HttpServlet{
    public void service(HttpServletRequest req, HttpServletResponse res)
            throws IOException, ServletException{
        System.out.println("CasRedirectServlet Called == " + TbuyHelper.getDashboardLocation());
        RequestDispatcher rd = req
                .getRequestDispatcher("/test.jsp");
        rd.include(req, res);
    }

test.jsp

代码
<%@ page import="tbuy.tbuyHelp"%>
<% response.sendRedirect("banana/index.html#/dashboard/file/tbuy.json"); %>

现在,我看到一个空白test.jsp。

响应。对给定URL的索引不起作用。

根据requestDisPatcher.include method

的doc

随附的servlet无法更改响应状态代码或设置 标题;

忽略了任何改变的尝试。

响应。通过发送302状态和位置标头来进行索引工作。因此,您的重定向在test.jsp中被忽略

编辑:看一下前进方法,它可能比包括。

更合适。

最新更新