0

I have my own internet site on localhost. The JSP page is working fine when I run the JSP files from NetBeans. also running fine when I run it from the browser. I made a simple Android application with a WebView. The application also runs fine when I try to load CNN site: But when I replace the URL with my own URL, I get the famous Error message: HTTP Status 404 - Not Found. I know that the URL is also fine because I can run it from the browser. The only difference is that my URL is on localhost. I'm using Android Emulator Nexus_6_API_23 Google_API:5554 I read in other's people answers that the emulator interact with localhost using IP 10.0.2.2, So I have changed the WebView URL as follow: from: http://localhost:8080/MissionWS/myLogin.jsp To: http://10.0.2.2:8080/MissionsWS/myLogin.jsp

Here is the code of the web view android application: Can anyone help?

public class MainActivity extends AppCompatActivity {
private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (WebView) findViewById(R.id.mWebView);
    mWebView.getSettings().setJavaScriptEnabled(true);
    //mWebView.loadUrl("http://edition.cnn.com/");
    mWebView.loadUrl("http://10.0.2.2:8080/MissionsWS/myLogin.jsp");
    }
}
Arghavan
  • 1,125
  • 1
  • 11
  • 17
Drovo
  • 5
  • 4

1 Answers1

0

You cannot access like that to the localhost. I think you should look over to : How can I access my localhost from my Android device?

takeCAway
  • 41
  • 4
  • Thanks for trying to help. this is was i have found: There is however a far better solution. You can access your host machine with the IP address "10.0.2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080". – Drovo Jun 23 '17 at 10:02
  • I did the same, and it but it is not working. If I run the url from the browser it works ! any other suggestions ?? – Drovo Jun 23 '17 at 10:03