Search code examples
javaservletslocalhostwebserver

How to access my webapp using public IP address instead of localhost?


Is it possible to access my web application using public IP address like,

http:/AppServerIP:8180/myWar/myServlet

If I hit through Web Server like below it works fine (Servlet gets invoked)

http:/WebServerIP(public)/myWar/myServlet

When am trying to invoke the Servlet from my Application Server, am getting the below exception.

java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at java.net.Socket.connect(Socket.java:478)

Servlet gets invoked internally through code when another end User concurrently logs into same port. So, I want to call that Servlet and invalidate the current session. I don't want to go through Web server as it might send the request to other ports as well.

My project Stack : Jboss AS 5.1.0 GA, Apache web server 2.2.5 and Port Number is 8180


Solution

  • First of all, you need to get your public IP address, which you can find using ipconfig command on Windows machine.

    Then, you can try like this

    http://<your_public_ip_address>:<your_webserver_port>/
    

    It will show you server welcome page. And you need to open your specific project. Then, try this

     http://<your_public_ip_address>:<your_webserver_port>/myproject/
    

    It will show, your index or home page of your project.

    Note : You need to be sure for your IP Address and Port Number