0 Replies Latest reply on Jun 14, 2007 9:35 AM by Anna Karina

    Can't get the right IP address when running inside JBoss

    Anna Karina Newbie


      I have the following code in a utility library and can return the right IP address just fine (e.g., when it is called from an independent Java program, or when it is called from some program running on Tomcat:

      InetAddress addr;
      try {
       addr = InetAddress.getLocalHost();
      } catch (UnknownHostException e) {
       return null;
      byte[] ipAddr = addr.getAddress();
      String ipAddrStr = "";
      for (int idx = 0; idx< ipAddr.length; idx++)
       if (idx > 0) {
       ipAddrStr += ".";
       ipAddrStr += ipAddr[idx]&0xFF;

      But when the same piece of code is invoked inside JBoss (from a Struts 2 action), this only returns "".

      Could someone tell what's going on, and how could I get the right IP address?