JSF 1.2-1.2_07-b03-FCS
JSTL 1_1-mr2 (special build)
Java 1.6.0_22-b04
Eclipse 3.6.0 (Helios)
Tomcat 6.0.28 (needs to run also on Weblogic)
IE 7.0.5730.13
Firefox: 6.0
We have page: http://{host:port}/mybase/faces/mypage.jsp...
It is called from multiple external pages via hyperlink, redirect, etc.
We would like to determine the URL of the page that called it (in order to implement a command button "back" button) in a pure "JSF" manner.
We know we can do this:
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletRequest origRequest =
(HttpServletRequest)externalContext.getRequest();
String referrer = origRequest.getHeader("referer");
This, however, requires the HttpServletRequest which requires including the servlet-api.jar file.
The question: can this be done in a pure JSF manner and thus, without including the servlet-api.jar file?
Thanks, J开发者_如何学Pythonohn
This, however, requires the HttpServletRequest which requires including the servlet-api.jar file
This makes no sense. JSF at its own has already a Servlet API dependency. Perhaps you're referring to the compilation error in your IDE because the project isn't associated with a target runtime at all? In that case, please read this carefully: How do I import the javax.servlet API in my Eclipse project?
As to the concrete question, just use ExternalContext#getRequestHeaderMap()
to get a mapping of the request headers.
String referrer = externalContext.getRequestHeaderMap().get("referer");
// ...
精彩评论