Traditional Culture Encyclopedia - Weather inquiry - How to use java for background development of mobile terminals?

How to use java for background development of mobile terminals?

When your customers encounter some problems, the enterprise can use the enterprise website to solve the problems encountered by customers. For example, if users encounter some problems, you can add some related content to your website, and users will see your information when searching for this problem, so that the problems encountered by customers will be solved after seeing the content of your website. ?

The method of developing the mobile terminal background with java: The first method: You can choose to use the programming structure of JavaEE to write, and you need to convert the HTML interface into other data, such as json and xml, and you can choose one of them. The second type: using httpurlconnection through the network server of tomact, the client establishes communication with the background, and directly connects with socket. Third, all-around programmers can use HTML5, css and JavaScript commonly used in the front end for development. Note: The principle of Javaweb background development is the same as that of mobile app, and the main difference is that the transmission data format of app background development and web is different.

Java developed in the mobile background is exactly the same as Java developed in the web background. Java native background framework servlet, if you use Java background open source framework, you can choose spring+springmvc+mybatis, or use ssh framework.

In fact, there are two common protocols for the interaction between foreground and background:

1http protocol.

HTTP is an object-oriented protocol, which belongs to the application layer. Because of its simple and fast way, it is suitable for distributed hypermedia information systems. It was put forward by 1990. After several years of use and development, it has been continuously improved and expanded. At present, the sixth edition of HTTP/ 1.0 is used in WWW, and the standardization of HTTP/ 1. 1 is in progress, and the suggestion of HTTP-NG(nextgenerationfhttp) is put forward. The main features of the HTTP protocol can be summarized as: 1. Support client/server mode. 2. Simple and fast: When the customer requests the service from the server, it only needs to transmit the request method and path. The commonly used request methods are GET, HEAD and POST. Each method specifies that the contact type between the client and the server is different. Because of the simplicity of HTTP protocol, the program scale of HTTP server is small, so the communication speed is very fast. 3. Flexibility: HTTP allows the transmission of any type of data object. The type of transmission is marked by the content type. 4. No connection: No connection means limiting each connection to one request. After the server has processed the customer's request and received the customer's reply, it will disconnect. This can save transmission time. 5. Stateless: HTTP protocol is stateless. Stateless means that the protocol has no memory for transaction processing. Lack of state means that if the previous information is needed for subsequent processing, it must be retransmitted, which may lead to an increase in the amount of data transmitted per connection. On the other hand, when the server doesn't need the previous information, it responds faster.

2webservice, an example is the weather forecast interface.

Webservice is a platform-independent, low-coupling, self-contained and programmable Web-based application. It can be described, published, discovered, coordinated and configured by using open XML (a subset of standard generalized markup language) standards to develop distributed and interoperable applications. [ 1]

WebService technology enables different applications running on different machines to exchange data or integrate with each other without the help of additional specialized third-party software or hardware. No matter what language, platform or internal protocol is used, applications implemented according to the WebService specification can exchange data with each other. WebService is a self-describing, self-contained and available network module, which can perform specific business functions. WebService are also easy to deploy, because they are based on some traditional industry standards and some existing technologies, such as subset XML and HTTP under standard generalized markup language. WebService reduces the cost of application program interface. WebService provides a general mechanism for business process integration between the whole enterprise and even multiple organizations.

Second, there are two commonly used data transmission formats in the foreground and background:

1xml

Brief introduction of three parsing methods of XML

The famous cathedral

It is no exaggeration to say that DOM is W3C's standard API for XML processing, and it is the basis of many other standards related to XML processing. Not only Java, but also other languages, such as Javascript, PHP and MS.NET, have achieved this standard and become the most widely used XML processing method. Of course, in order to provide more and more powerful functions, Java has many tools to directly extend DOM, such as JDOM and DOM4J, which are familiar to many Java programmers. They are basically extensions of DOM interface functions and retain many DOMAPI features. Many original DOM programmers have mastered the use of the other two without any obstacles, and their intuitive and easy-to-operate methods have also made them popular with Java programmers.

Environmental protection saxophone

The emergence of SAX has its special needs. Why is it green? This is because SAX uses the least system resources and the fastest parsing method to support XML processing. However, the complex search method also brings a lot of trouble to programmers, which is often a headache. At the same time, its support for XPath query function makes people love and hate.

Obscure Digester: JavaBeanization of XML

Digester is an open source project under apache Foundation. The author's understanding of it stems from the research on Struts framework. Are there many programmers who want to know the design of major open source frameworks, or even want to write a powerful framework themselves? They will encounter such a difficult problem: what technology is used to analyze these various framework configuration files marked in XML language? DOM parsing is time-consuming, SAX parsing is too complicated, and the system overhead will be too high every time. So I thought I needed JavaBean with corresponding XML structures to load this information, and Digester came into being. Its appearance brings a convenient operation interface for the requirement of transforming XML into JavaBean objects, which makes more similar requirements solved perfectly, and it is no longer necessary for programmers to realize such complicated parsing programs themselves. At the same time, SUN also introduced JAXB, an XML and JavaBean conversion tool class, which interested readers can learn by themselves.

2json

JSON(JavaScriptObjectNotation) is a lightweight data exchange format. It is based on a subset of ECMAScript. JSON adopts a completely language-independent text format, but it also uses habits similar to the C language family (including C, C++, C#, Java, JavaScript, Perl, Python, etc.). These characteristics make JSON an ideal data exchange language. It is convenient for people to read and write, and it is also convenient for machine analysis and generation (generally used to improve network transmission rate).

Three examples of Android learning

If you want to know the examples of interaction between Android and the background, you can go to the 360 mobile assistant to download the Android learning manual, which contains a large number of Android examples and detailed explanations of http protocol, and the source code and documents can be read. The following is a screenshot of an example.