归志宁无五亩园,读书本意在元元。这篇文章主要讲述Javaweb中利用rpc(hessian)与Android通信相关的知识,希望能为你提供帮助。
一、服务端(tomcat)
1.需要引入的包hessian-4.0.60.jar 下载链接:https://files.cnblogs.com/files/javabull/hessian-4.0.60.zip
2.编写实体类
1 package com.javabull.inter.entity; 2 3 public class User { 4private String name; 5private String password; 6public String getName() { 7return name; 8} 9public void setName(String name) { 10this.name = name; 11} 12public String getPassword() { 13return password; 14} 15public void setPassword(String password) { 16this.password = password; 17} 18public User(String name, String password) { 19super(); 20this.name = name; 21this.password = password; 22} 23public User() { 24super(); 25} 26 27 }
3.编写接口com.javabull.inter.InterManager
1 package com.javabull.inter; 2 3 import com.javabull.inter.entity.User; 4 5 public interface InterManager { 6public boolean loginCheck(User user); 7 }
4.编写实现类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 9public boolean loginCheck(User user) { 10boolean ret = false; 11if(user!=null & & user.getName()!=null & & user.getPassword()!=null) { 12if (user.getName().equals("javabull")& & user.getPassword().equals("123456")) { 13ret = true; 14} 15} 16return ret; 17} 18 19 }
5.配置web.xml文件
1 < ?xml version="1.0" encoding="UTF-8"?> 2 < web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3xmlns="http://java.sun.com/xml/ns/javaee" 4xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 5id="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>
二、android客户端
1..包的引入:https://files.cnblogs.com/files/javabull/android_hessian.zip
2.使用
【Javaweb中利用rpc(hessian)与Android通信】 1 InterManager interManager = (InterManager)HessianProxyFactory.create(InterManager.class,"http://192.168.1.153"); //之后即可调用接口中的方法了
推荐阅读
- Cocos2d-x Android环境中Lua脚本的io操作
- Springboot2-application.properties文件中文注释都是unicode编码
- redis报错Bad file format reading the append only file: make a backup of your AOF file, then use ./
- uni-app:如何绑定新字段在已有的列表中
- ReactNative: 使用AppState的API获取App的状态
- uni appuni ui的引入和调用
- Appium+Pytest实现app并发测试
- @SpringBootApplication的说明
- webapp开发之IIS进程调试