-
1. Re: Programmatic Access to Server URL
jonlee Nov 20, 2003 5:08 PM (in response to hreynolds2)Have a look at the various request APIs for servlets (HttpServletRequest and parent).
request.getServerPort()
request.getServerName()
request.getURI()
And so on. -
2. Re: Programmatic Access to Server URL
hreynolds2 Nov 21, 2003 9:35 AM (in response to hreynolds2)gotta love the newbie questions!!! thx,
~harris -
3. Re: Programmatic Access to Server URL
hreynolds2 Nov 21, 2003 9:38 AM (in response to hreynolds2)There is a key piece to my question that I left out.... is there a way to get the port of the server you are running on in the servlet init method (*before* the first request comes in)?
That's the API I'm looking for and I'm imagining it'd need to be container specific.
thanks,
~harris -
4. Re: Programmatic Access to Server URL
jonlee Nov 21, 2003 4:20 PM (in response to hreynolds2)AFAIK, no. The servlet has no concept of this since it can serve any request passed on to it from a listener/connector. So you could have a listener on port 8080 passing a request on, as well as a listener on port 80 doing the same. The init is used when the servlet is first created, but once created, it can receive requests from any listener/connector on the server. That's why the information on the URI, etc is contained in the request.
You could specifically provide a value via initparam by I would think this is a bit inflexible. YMMV.