如何解决从jsp重定向jsp-错误“请求的资源不可用。”?

如果响应是相对于servlet上下文的,则在URL之前添加上下文路径。

String contextpath = request.getcontextpath();
response.sendRedirect(response.encodeRedirectURL(contextpath + "/profile.jsp");

解决方法

我在一个社交网站上工作,但遇到以下问题。在profile.jsp我的表格中,用户可以上传照片。此表单对FileUploadHandlerservlet
有一个操作,该操作会上传照片,然后将重定向发送至,uploadfileController.jsp如下所示:

RequestDispatcher requestDispatcher;
requestDispatcher = request.getRequestDispatcher("/uploadfileController.jsp");
requestDispatcher.forward(request,response);

在中,uploadfileController.jsp我将此帖子插入到MySQL数据库中,并将重定向发送到profile.jsp

response.sendRedirect("/profile.jsp");

但是然后我收到此错误消息:

HTTP状态404-/profile.jsp

类型状态报告

消息/profile.jsp

描述所请求的资源不可用。

但是,当我再次转到profile.jsp该帖子时就创建了!有任何想法吗?