File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to get server IP address? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get server IP address?" Watch "How to get server IP address?" New topic
Author

How to get server IP address?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
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
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

See:
request.getLocalAddr


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
That method exists since v2.4, but we must be running earlier (java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
)...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get server IP address?