javaservletsmobile

Accessing a Java Web Application via Mobile


I have a basic web application written in Java, running on a Tomcat on my localhost. Currently it's just a simple application with a single servlet to which I access from my browser. I want to write a mobile Android application which will be the client of my Java web application. I want the servlet to write to a database and do some logic, but to access it from a mobile app.

Currently I don't have any domain registered.

How can I expose my Java web app so that in my development environment I would be able to access it via my mobile device? Meaning, currently it runs locally on my PC and I access from the browser (on localhost). I want to access it from a different device (mobile) - how can it be done in my home LAN?


Solution

  • If the web app is hosted on your local server, your mobile will need to be able to access the IP address (ie: 192.168.1.100) and port (ie: 8080) that is hosting the app.

    There are several ways to allow your mobile to communicate to your desktop:

    1. Direct connection via USB or Bluetooth.
    2. Wireless connection on your LAN - if your mobile can connect wirelessly to your home LAN, you should be able to access your web app (your desktop's firewall may have to open up your web port)
    3. External access. This requires opening up your home network to allow access to your desktop's web port. Also your internet router would have to be configured to allow access and likely do a NAT translation. Note that in this scenario, anybody can access your web app so be very careful. You would also need to use your external IP address instead of your internal LAN address.

    A domain is only required to allow the use of a name (http://www.example.com) instead of your IP address.