一、下载Hessian
可在hessian官网http://hessian.caucho.com/ 或者http://download.csdn.net/detail/wodediqizhang/9543682下载jar包。此处用的是hessian-4.0.3.jar
二、 搭建Hessian的Server
2.1.新建一个web项目,HessianTest,如图1。将hessian-4.0.3.jar放在lib下。
2.2.提供服务接口HessianService,代码如下:
2.3.HessianService接口要使用HelloWorld对象,HelloWorld代码如下:
2.4.实现HessianService接口,实现类为HessianServiceImpl:
2.5.配置web.xml,添加对HessianServlet的配置:
此时,Hessian Server的配置已经完成了,接下来将应用部署在tomcat并启动。访问链接http://127.0.0.1:8081/HessianTest/ServiceServlet,得到信息如下:
三、实现Hessian的client
调用Hessian的客户端,创建HessianTestClient类,代码如下:
后记:这篇博是借鉴了孤傲苍狼(http://www.cnblogs.com/xdp-gacl/p/3897534.html)这篇文章的内容实现的,不过他是将server和client分开,并将server的接口打了jar包给client,在client项目里面引用jar包里的接口实现对server的调用。这里我觉得理解原理就好,所以就我在这里就写一起了。
再后记:上个后记都说了借鉴,那这篇文章还设为转载吧。就这样。