Javaweb utilized rpc (hessian) communicate with Android

First, the server (tomcat)

  1. The need to introduce a package hessian 4.0.60.jar-download link: https: //files.cnblogs.com/files/javabull/hessian-4.0.60.zip

  2. Write the entity class

  

 1 package com.javabull.inter.entity;
 2 
 3 public class User {
 4     private String name;
 5     private String password;
 6     public String getName() {
 7         return name;
 8     }
 9     public void setName(String name) {
10         this.name = name;
11     }
12     public String getPassword() {
13         return password;
14     }
15     public void setPassword(String password) {
16         this.password = password;
17     }
18     public User(String name, String password) {
19         super();
20         this.name = name;
21         this.password = password;
22     }
23     public User() {
24         super();
25     }
26         
27 }

 

  3. Write Interface com.javabull.inter.InterManager

    

1  the package of comjavabullinter;
2 for  
3 in a  import The comjavabullinterentityUser;
The 4  
of 5  , public  for interface InterManager {
 of 6      , public  Boolean loginCheck (the User-with user);
7 }

 

  4. Preparation of implementation class com.javabull.inter.impl.InterManagerImpl

 1 package com.javabull.inter.impl;
 2 
 3 import com.javabull.inter.InterManager;
 4 import com.javabull.inter.entity.User;
 5 
 6 public class InterManagerImpl implements InterManager{
 7 
 8     @Override
 9     public boolean loginCheck(User user) {
10         boolean ret = false;
11         if(user!=null && user.getName()!=null && user.getPassword()!=null) {
12             if (user.getName().equals("javabull")&&user.getPassword().equals("123456")) {
13                 ret = true;
14             }
15         }
16         return ret;
17     }
18 
19 }

   5. Configure web.xml file

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xmlns="http://java.sun.com/xml/ns/javaee"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 5     id="WebApp_ID" version="3.0">
 6 
 7     <display-name>TestHessian</display-name>
 8     <welcome-file-list>
 9         <welcome-file>index.jsp</welcome-file>
10     </welcome-file-list>
11     
12     <servlet>
13         <servlet-name>server</servlet-name>
14         <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
15         <init-param>
16             <!-- 接口实现 -->
17             <param-name>home-class</param-name>
18             <param-value>com.javabull.inter.impl.InterManagerImpl</param-value>
19         </init-param>
20         <init-param>
21             <!-- 接口 -->
22             <param-name>home-api</param-name>
23             <param-value>com.javabull.inter.InterManager</param-value>
24         </init-param>
25     </servlet>
26     <servlet-mapping>
27         <servlet-name>server</servlet-name>
28         <url-pattern>/server.do</url-pattern>
29     </servlet-mapping>
30 </web-app>

  Two, Android Client

    1 .. package introduced: https: //files.cnblogs.com/files/javabull/android_hessian.zip

    2. Use

   . 1 InterManager InterManager = (InterManager) HessianProxyFactory.create (InterManager. Class , "http://192.168.1.153" );  // interface methods can be invoked after the 

Guess you like

Origin www.cnblogs.com/javabull/p/12119723.html
RPC
RPC