Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HttpServletRequest getServerName returning internal IP address

Posted on 2008-10-08
1
Medium Priority
?
2,572 Views
Last Modified: 2013-11-24
public String getWebrootUrl() {
            if (webrootUrl.length() == 0) {
                  HttpServletRequest request = FacesUtils.getRequest();
                  if (request != null) {
                        try {
                              URL reconstructedURL = new URL(request.getScheme(),
                                          request.getServerName(),
                                          request.getServerPort(),
                                          getWebroot());
                              webrootUrl = reconstructedURL.toString();
                        } catch (MalformedURLException e) {
                              webrootUrl = "";
                        }
                  }
            }
            return webrootUrl;
      }

The above code is use to generate the correct url when we were using a virtual name-based server, we've since moved off using named-based and switched to an IP based scheme so instead of returning somehting like https://www.myurl.com/ it now returns https://192.168.200.10 on our production server which is obviously a private network IP! Is there a way to get code to do a reverse-lookup on the IP in the local /etc/hosts file?

0
Comment
Question by:mhp2007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
Jorge Fraser earned 2000 total points
ID: 22669901
Look at InetAddress and the getHostName() method. It is supposed to do a reverse lookup for you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
A solution for Fortify Path Manipulation.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question