Hessian 简单例子
编程技术  /  houtizong 发布于 3年前   113
hello.hessian.MyCar.java
package hessian.pojo;import java.io.Serializable;public class MyCar implements Serializable { private static final long serialVersionUID = 4736905401908455439L; private String carName; private String carModel; public String getCarName() { return carName; } public String getCarModel() { return carModel; } public void setCarName(String pCarName) { carName = pCarName; } public void setCarModel(String pCarModel) { carModel = pCarModel; } @Override public String toString() { return "my car name:[" + this.carName + "] model:[" + this.carModel + "]."; }}
hessian.service.HelloHessian.java
package hessian.service;import hessian.pojo.MyCar;import java.util.List;import java.util.Map;public interface HelloHessian { String sayHello(); MyCar getMyCar(); List myLoveFruit(); Map myBabays();}
hessian.service.impl.HelloHessianImpl.java
package hessian.service.impl;import com.caucho.hessian.server.HessianServlet;import hessian.pojo.MyCar;import hessian.service.HelloHessian;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;public class HelloHessianImpl extends HessianServlet implements HelloHessian { public MyCar getMyCar() { MyCar car = new MyCar(); car.setCarName("阿斯顿·马丁"); car.setCarModel("One-77"); return car; } public Map myBabays() { Map map = new HashMap(); map.put("son", "孙吴空"); map.put("daughter", "孙小美"); return map; } public List myLoveFruit() { List list = new ArrayList(); list.add("apple"); list.add("kiwi"); list.add("orange"); return list; } public String sayHello() { return "welcom to Hessian"; }}
hessian.Main.java
package hessian;import com.caucho.hessian.client.HessianProxyFactory;import hessian.service.HelloHessian;public class Main { public static String url = "http://localhost:8888/InfoWeb/Hello"; public static void main(String[] args)throws Exception{ HessianProxyFactory factory = new HessianProxyFactory(); HelloHessian helloHession = (HelloHessian) factory.create(HelloHessian.class, url); System.out.println(helloHession.sayHello()); System.out.println(helloHession.getMyCar()); System.out.println(helloHession.myBabays()); System.out.println(helloHession.myLoveFruit()); }}
web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app><servlet><servlet-name>Hello</servlet-name><servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class><init-param><param-name>home-class</param-name><param-value>hession.service.impl.HelloHessianImpl</param-value></init-param><init-param><param-name>home-api</param-name><param-value>hession.service.HelloHessian</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>Hello</servlet-name><url-pattern>/Hello</url-pattern></servlet-mapping></web-app>
pom.xml
<dependencies> <!--=========================== hession =========================== --> <dependency> <groupId>com.caucho</groupId> <artifactId>hessian</artifactId> <version>4.0.33</version> </dependency> <!--=========================== Servlet Api ===========================--> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> </dependencies>
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接