Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get server IP address?

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I get the IP address of my servlets' server?

I am wanting it so my client call http://myIpAddress/myServletContext/myServlet instead of http://myDomain.com/myServletContext/myServlet

In my processRequest method, I've tried:


but when I try to connect to the servlet replacing myDomain.com with the IP address from the code, I get a code 404. The online IP address finders give the same incorrect IP. How can I solve?

Cheers,
James
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That method exists since v2.4, but we must be running earlier (java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
)...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic