In Android, sometimes we don't need to use the local SQLite database to provide data, more often from the network to get data, then how does Android get data from the server? There are many kinds of
1: Obtain data method based on HTTP protocol.
2: Data acquisition method based on SAOP protocol.
3: forget-------
So our article is mainly about using the HTTP protocol to obtain server-side data, where we take the server-side technology for Java, the framework for STRUTS2, or can have a servlet, or directly from the JSP page to get data.
So, then we start the journey:
First: Write the server-side method, I used here the MVC framework is STRUTS2, the purpose is very simple, is to do a complete business project, the technology is equipped with: Android+ssh. Of course, space is limited, I am here directly with Strtus2 just.
Server side: New WebProject, choose Java EE 5.0.
In order to add STRUTS2 support to the project, we have to import some of the class libraries of Struts2, such as the following (some of the jar packages are not necessary, but we can later expand to be used, we get in first):
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 processing JSON format data to use to
10:struts2-json-plugin-2.2.1.1.jar JSON plugin based on STRUTS2
The above jar package needs to be placed under the Webroot/web-inf/lib directory
Then knock down in the Web.xml file:
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 place it in the Webroot/web-inf/lib directory: The following code:
"-//apache Software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >