I am running my application in localhost, port 8080. The base url is: http://localhost:8080/EMSApplication/otherparts...
Now from HttpServletRequest how can I extract the portion http://localhost:8080/EMSApplication ?
Currently I am doing this:
String schema = request.getScheme();
String serverName = request.getServerName();
int serverPort = request.getServerPort();
String contextPath = request.getContextPath();
String path = schema + "://" + serverName + ":" + serverPort + contextPath;
System.out.println(path);
Here request is the instance of HttpServletRequest.
Is this procedure right?
Is there any other way to get the information?
If I host my application and say the URL is http://my.domain.com/EMSApplication/otherparts... then there the aforesaid procedure code will work?
Another way I found:
String requestUrl = request.getRequestURL().toString();
String contextPath = request.getContextPath();
String path = requestUrl.substring(0, requestUrl.indexOf(contextPath) + contextPath.length());
Where I need this:
HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();
String requestUrl = request.getRequestURL().toString();
String contextPath = request.getContextPath();
String path = requestUrl.substring(0, requestUrl.indexOf(contextPath) + contextPath.length());
submitLink.add(new WebMarkupContainer("submitImage").add(new AttributeModifier("src", path + "/ASSETS/css/images/login-btn.png")));
I am developing an Wicket application where I need to specify src of an <img/>.