bugs_
bugs_

Reputation: 3744

How to get Server Name, Port and Context

I have Java Web app.

I need get its URL where it is running (e.g. http://myserver:8080/mycontext).

I need it because I want to be able construct URL on some resource, that has been created.

e.g. By soap request was created resource /myresource and I need insert into soap response reference on this resource (http://myserver:8080/mycontext/myresource)

And I need to be able return URL on resource even when message come from JMS.

  1. Is it possible to determine application URL during startup? e.g. in ServletContextListener.
  2. Or how it is beeing solved?

Upvotes: 1

Views: 1489

Answers (1)

adarshr
adarshr

Reputation: 62603

You can get all those from the HttpServletRequest object, if you can get a hold of it.

Upvotes: 1

Related Questions