我正在开发一个社交网站,但遇到以下问题。在 profile.jsp
我有一个用户可以上传照片的表单。此表单有一个操作 FileUploadHandler
servlet 上传照片,然后将重定向发送到 uploadfileController.jsp
像这样:
RequestDispatcher requestDispatcher;
requestDispatcher = request.getRequestDispatcher("/uploadfileController.jsp");
requestDispatcher.forward(request, response);
在 uploadfileController.jsp
我将这篇文章插入到我的 MySQL 数据库中,并将重定向发送到 profile.jsp
。
response.sendRedirect("/profile.jsp");
但随后我收到此错误消息:
HTTP Status 404 - /profile.jsp
type Status report
message /profile.jsp
description The requested resource is not available.
但是,当我再次访问profile.jsp
时帖子已创建!有什么想法吗?
最佳答案
如果响应与 servlet 上下文相关,则在 URL 前面添加上下文路径。
String contextPath = request.getContextPath();
response.sendRedirect(response.encodeRedirectURL(contextPath + "/profile.jsp");
关于java - 从 JSP 重定向 JSP - 错误 "The requested resource is not available.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28008863/