简体   繁体   中英

Fail to load url on WebView

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");
    }
}

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM