• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I get port number and server host name by java code in my JSP  RSS feed

 
Talitha Bell
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have web application ,I want to get port number and host name of the server (by java code)which run this application in my jsp.

For example :http://localhost:8080/mycontext,
here 8080 is server port and localhost is host ,



Any help would be very appreciable
.
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use methods from ServletRequest interface for this:

getLocalAddr()(for the IP), getLocalName() (Spec says: Returns the host name of the Internet Protocol (IP) interface on which the request was received),getServerPort() (port to which the request was originally sent),getLocalPort() (port number of the interface in which the request ended up) .
 
Talitha Bell
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply
[ December 05, 2008: Message edited by: Talitha Bell ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!