Several Methods for Android to obtain data from the server
In android, sometimes we don't need to use the local SQLite database to provide data. More often, we need to get data from the network. How can Android get data from the server? There are many types.
I. Methods for obtaining data based on Http protocol. Ii. Methods for obtaining data based on the SAOP protocol; 3. Forgot -------
In this article, we will mainly discuss how to use the Http protocol to obtain server-side data. Here we adopt the server-side technology as java, and the framework as Struts2, or we can have Servlet, or you can directly obtain data from the JSP page.
Then, let's start this journey:
First of all: Compile the server method. The MVC framework I use here is Struts2. The purpose is very simple. It is to create a complete commercial project in the future. The technical configuration is android + SSH. Of course, the length is limited. I will use Strtus2 directly here.
Server: Create a WebProject and select Java ee 5.0.
To add Struts2 support to the project, we must import some Struts2 class libraries as follows (some jar packages are not required, but we may need to use the extension later, ):
1: xwork-core-2.2.1.1.jar
2: struts2-core-2.2.1.1.jar
3: commons-logging-1.0.4.jar
4: freemarker-2.3.16.jar
5: ognl-3.0.jar
6: javassist-3.7.ga.jar
7: commons-ileupload.jar
8: commons-io.jar
9: json-lib-2.1-jdk15.jar to process JSON format data to use
10: struts2-based struts2-json-plugin-2.2.1.1.jar json plugin
The above jar package needs to be placed in the WebRoot/WEB-INF/lib directory
In the web. xml file, click:
View Code
Xmlns = "http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd>
Struts2
Org. apache. struts2.dispatcher. FilterDispatcher
Struts2
/*
Index. jsp
Then write the struts. xml file and put it in the WebRoot/WEB-INF/lib directory: the following code:
View Code
"-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN"
Http://struts.apache.org/dtds/struts-2.0.dtd>