views:

25

answers:

2

Hey,

Is there any way I can get url address of an application from java code, I mean complete address not only value from getContextPath(). Something like http://localhost:8080/etc

A: 

Try with getRequestUrl().

I hope it helps you

Aito
A: 

In a servlet or JSP, you can call javax.servlet.http.HttpUtils.getRequestURL(request)

It returns a StringBuffer containing the entire URL up to the servlet

From the javadoc

Reconstructs the URL the client used to make the request, using information in the HttpServletRequest object. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

If you only want up to the context path, you'll have to remove your servlet path

karoberts