cancel
Showing results for 
Search instead for 
Did you mean: 

Get server - URL

webdesigner
Champ in-the-making
Champ in-the-making
Hello,

I do following to obtain server URL like http://localhost:8080:

HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
//Request URL
final String requestURL = request.getRequestURL().toString();
//Context path
final String requestcontextPath = request.getContextPath();
//Server - URL
this.serverUrl = requestURL.substring(0,
   requestURL.indexOf(requestcontextPath));

But it looks like dirty hack (from servlet programming time).

Is there another way to get the same? (From subclass of BaseWizardBean)
1 REPLY 1

kevinr
Star Contributor
Star Contributor
As you are within a Faces app that is the way to do it, it's looks icky but that's because Faces tries to "hide" the underlying implementation which is why you need to jump through some annoying hoops.

Thanks,

Kevin