从jsp重定向jsp - 错误“请求的资源不可用。” [英] Redirect jsp from jsp - error "The requested resource is not available."

查看:2239
本文介绍了从jsp重定向jsp - 错误“请求的资源不可用。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在社交网站上工作,我遇到以下问题。在 profile.jsp 我有一个用户可以上传照片的表单。此表单有一个 FileUploadHandler servlet的操作,它上传照片,然后将重定向发送到 uploadfileController.jsp ,如下所示:

I'm working on a social networking site and I have the following problem. In profile.jsp I have a form where the user can upload a photo. This form has an action to FileUploadHandler servlet which uploads the photo and then sends redirect to uploadfileController.jsp like this:

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

uploadfileController.jsp 我插入这篇文章进入我的MySQL数据库,我发送重定向到 profile.jsp

In uploadfileController.jsp I insert this post into my MySQL database and I send redirect to profile.jsp.

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

然后我收到此错误消息:

But then I get this error message:

HTTP状态404 - /profile.jsp

HTTP Status 404 - /profile.jsp

类型状态报告

消息/profile.jsp

message /profile.jsp

描述请求的资源不可用。

description The requested resource is not available.

但是,当我再次去 profile.jsp 时,帖子就会被创建!任何想法?

However, when I go again to profile.jsp the post is created! Any ideas?

推荐答案

如果响应是相对于servlet上下文的,那么将上下文路径预先添加到URL。

If the response is relative to servlet context then prepend context path to the URL.

String contextPath = request.getContextPath();
response.sendRedirect(response.encodeRedirectURL(contextPath + "/profile.jsp"); 

这篇关于从jsp重定向jsp - 错误“请求的资源不可用。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆