jsf - Custom error page - get originally requested URL -
problem
this follow-up yesterday's (unanswered) question (see here) try find alternative approach.
i added basic
<error-page> <error-code>404</error-code> <location>/404search.jsf</location> </error-page>
..to web.xml
. need url user entered submit search function, manage current url (in case, ...404search.jsf
) instead of actual query user entered.
attempts
httpservletrequest.getrequesturl
returnshttp://www.website.com/foldername/404search.jsf
httpservletrequest.getrequesturi
returns/foldername/404search.jsf
httpservletrequest.getquerystring
returns nothing @ all
i want return /foldername/wrong-url-the-user-entered#anchor-if-there-is-any
details...
the idea url user entered (such www.site.com/product/99999-product-that-cant-be-found
or www.site.com/faq/support-question-that-doesnt-exist
), regex remove hyphens , run search query 99999 product cant found
or support question doesnt exist
.
any suggestions?
the <error-page>
under covers served requestdispatcher#forward()
call. details of original request available request attribues keyed keys identified requestdispatcher#forward_xxx
constants:
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"
you starter should know request attributes in el available via implicit el object #{requestscope}
.
so, all, should in view:
<p>unfortunately, page requested, #{requestscope['javax.servlet.forward.request_uri']} not exist</p>
and equivalently, should in bean, if necessary:
string forwardrequesturi = externalcontext.getrequestmap().get(requestdispatcher.forward_request_uri);
Comments
Post a Comment