[OmniFaces utilities] The
getRequestBaseURL()
method returns the HTTP request base URL. This is the URL from the scheme, domain until with context path, including the trailing slash. This is the value you could use in HTML <base>
tag.Method:
See also: Servlets#getRequestDomainURL()
Usage:
·
inside a servlet filter or even a plain
vanilla servlet (basically, when FacesContext is not available):
import
org.omnifaces.util.Servlets;
...
@WebServlet("/MyServlet")
public class
MyServlet extends HttpServlet {
protected void
processRequest(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// e.g.
http://localhost:8080/MyApp/
String baseURL = Servlets.getRequestBaseURL(request);
}
...
}
·
in JSF, when FacesContext is available use, Faces#getRequestBaseURL(), or more clumsy (not recommended):
import
org.omnifaces.util.Servlets;
...
// or simply
use, Faces#getRequest()
FacesContext
context = FacesContext.getCurrentInstance();
ExternalContext
externalContext = context.getExternalContext();
HttpServletRequest
request = (HttpServletRequest) externalContext.getRequest();
// e.g. http://localhost:8080/MyApp/
String baseURL =
Servlets.getRequestBaseURL(request);
Niciun comentariu :
Trimiteți un comentariu