How to access a local Web application on the Android emulator

Source: Internet
Author: User
Tags web services java web tomcat

This article attempts to address the question of how to access a local Web application on the Android emulator. For example, start a Tomcat service on your development machine, then open the browser on your computer, and by default you can access Tomcat's home page by typing http://localhost:8080/, so if we want to access the Android emulator, can we? The answer is yes, but the URL of the visit will change. Please continue to look down.

In general Java Web Application development, we typically use localhost or 127.0 0.1来 to access native Web services, but if we use the same address in the Android emulator, the Android emulator will not be able to access our services properly. What is this for? We can understand that: the bottom of the aatchndroid is the Linux kernel, including Android itself is an operating system, so we entered in the emulator browser localhost or 127.0.0.1 generation It's the Android simulator (Android virtual machine), not your computer, okay? This is why you will report "Web page not available" When you use localhost in the emulator.

So how do you get access to Web apps on your local computer? In Android, the address of our local computer is mapped to 10.0.2.2, so you can access the Web resources on the local computer on the emulator simply by replacing the original localhost or 127.0.0.1 with 10.0.2.2.

So let's start Tomcat on the computer, then run the Android emulator, open the browser on the emulator, and then visit: http://10.0.2.2:8888 have you seen that cute tomcat cat? The access screenshot is shown in the following figure. (Note: On my computer, the Tomcat service uses a port of 8888, the default is 8080)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.