• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the ip address, port and context path from a Servlet's init method

 
juan velez
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to determine the URL a client app would need to use to access a web app (example: http://172.30.56.114:8080/ESBSimTPDEV25) from a Servlet's init method. I know how to do this using an HttpRequest object, but I need to do this before any actual request can hit the App Server. I tried looking into both ServletConfig and ServletContext but they do not seem to have the information I am looking for. Well, I know how to get the ip adresss but the port and context path do not seem to be something available, or is it?

thanks
[ October 15, 2007: Message edited by: juan velez ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is that you mean by "namespace"? The servlet mapping?

If so, this is not something you can know from the servlet, as any number of mappings can resolve to the same servlet.

What is it that you are actually trying to accomplish? Perhaps there's a better way of doing it.
[ October 15, 2007: Message edited by: Bear Bibeault ]
 
juan velez
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need the 3 components, ip address, port and the namespace for the webapp, the name you type to access the web application as explained in my example.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be the context path.

The ability to obtain the context path from the servletContext was added with Servlets 2.5.

Again, why are you trying to do this? I do not know of any way to obtain the port.
[ October 15, 2007: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not possible for a servlet to know these when it initializes.

A container can be configured to multiple URLs and IPs.
That is why the methods that that return these values belong to HttpServletRequest and it's superclass ServletRequest.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!