tsc*_*tsc 5 jsf servlets http-status-code-404
问题
当我尝试寻找替代方法时,这是对昨天(未答复)问题(见此处)的后续跟进.
我添加了基本的
<error-page>
<error-code>404</error-code>
<location>/404search.jsf</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
..到我的web.xml.我现在需要获取用户输入的URL以提交给我的搜索功能,但我只设法获取当前URL(在这种情况下,... 404search.jsf)而不是用户输入的实际查询.
尝试
HttpServletRequest.getRequestURL 回报 http://www.website.com/foldername/404search.jsfHttpServletRequest.getRequestURI 回报 /foldername/404search.jsfHttpServletRequest.getQueryString 什么都不回报我想要它回来 /foldername/wrong-url-the-user-entered#anchor-if-there-is-any
细节...
想法是获取用户输入的URL(例如www.site.com/product/99999-product-that-cant-be-found或www.site.com/faq/support-question-that-doesnt-exist),REGEX它以删除连字符并使用99999 product that cant be found或运行搜索查询support question that doesnt exist.
有什么建议?
Bal*_*usC 12
这<error-page>是一个RequestDispatcher#forward()电话覆盖的封面.原始请求的所有详细信息都可以作为请求属性提供,这些属性由RequestDispatcher#FORWARD_XXX常量标识的键来键入:
FORWARD_CONTEXT_PATH: "javax.servlet.forward.context_path"FORWARD_PATH_INFO: "javax.servlet.forward.path_info"FORWARD_QUERY_STRING: "javax.servlet.forward.query_string"FORWARD_REQUEST_URI: "javax.servlet.forward.request_uri"FORWARD_SERVLET_PATH: "javax.servlet.forward.servlet_path"作为入门者,您应该知道所有请求属性都是通过隐式EL对象 在EL中提供的#{requestScope}.
所以,总而言之,这应该在视图中做到:
<p>Unfortunately, the page you requested, #{requestScope['javax.servlet.forward.request_uri']} does not exist</p>
Run Code Online (Sandbox Code Playgroud)
并且等效地,如果需要,这应该在bean中执行:
String forwardRequestURI = externalContext.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1339 次 |
| 最近记录: |