java中使用Hessian基本步骤
来源:互联网 发布:pc数据恢复软件下载 编辑:程序博客网 时间:2024/06/03 13:43
Hessian 是由 caucho 提供的一个基于 binary-RPC 实现的远程通讯 library
(原理分析相关链接http://www.cnblogs.com/happyday56/p/4268249.html)
在java中使用Hessian可以实现不同项目之间取得联系同时又相对独立,降低了程序的耦合性,方便程序员进行维护和再次开发,以下是使用Hessian的简单步骤:
1、下载相应的jar包(http://hessian.caucho.com/ 或http://download.csdn.net/detail/wodediqizhang/9543682),比如hessian-4.0.3.jar;
2、定义对外提供服务的接口:
package com.cn.a.service; import com.cn.a.model.HelloWorld;public interface HessianService { public HelloWorld sayHelloWorld(); }
3、HessianService接口要使用HelloWorld对象:package com.cn.a.model; import java.io.Serializable; public class HelloWorld implements Serializable{private String name; public HelloWorld() { } public HelloWorld(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
3、实现HessianService接口,实现类为HessianServiceImpl:package com.cn.wjztr.service.impl; import com.cn.a.model.HelloWorld; import com.cn.a.service.HessianService;public class HessianServiceImpl implements HessianService { @Override public HelloWorld sayHelloWorld() { // TODO Auto-generated method stub return new HelloWorld("hello,World"); } }4、配置web.xml,添加对HessianServlet的配置:<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <!-- 配置 HessianServlet,Servlet的命名任意--> <servlet-name>ServiceServlet</servlet-name> <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class> <!-- 配置接口的具体实现类 ,param-name命名任意--> <init-param> <param-name>service-class</param-name> <param-value>com.cn.wjztr.service.impl.HessianServiceImpl</param-value> </init-param> </servlet> <!-- 映射 HessianServlet的访问URL地址--> <servlet-mapping> <servlet-name>ServiceServlet</servlet-name> <url-pattern>/ServiceServlet</url-pattern> </servlet-mapping> </web-app>此时,Hessian Server的配置已经完成了,接下来将应用部署在tomcat并启动。访问链接http://127.0.0.1:8081/HessianTest/ServiceServlet,得到信息如下:实现Hessian的client:
调用Hessian的客户端,创建HessianTestClient类,代码如下:
package com.cn.a.controller; import java.net.MalformedURLException; import com.caucho.hessian.client.HessianProxyFactory; import com.cn.a.model.HelloWorld; import com.cn.a.service.HessianService;public class HessianTestClient { public static void main(String[] args) { //在服务器端的web.xml文件中配置的HessianServlet映射的访问URL地址 String url = "http://127.0.0.1:8081/HessianTest/ServiceServlet"; HessianProxyFactory factory = new HessianProxyFactory(); HessianService service = null; try {service = (HessianService) factory.create(HessianService.class, url);} catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace();} //创建IService接口的实例对象 HelloWorld helloWorld = service.sayHelloWorld(); //调用Hessian服务器端的ServiceImpl类中的getUser方法来获取一个User对象 System.out.println(helloWorld.getName());}} } }
jsp页面:<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> 运行这个类,会得到“hello,World”信息:</span>
阅读全文
1 0
- java中使用Hessian基本步骤
- hessian(一)--基本使用
- Hessian的基本使用
- Java:Hessian框架使用
- 在应用中使用 Hessian
- 在SSH中使用Hessian
- Hessian学习(1)——基本使用
- OpenGL中使用Shader的基本步骤
- Android中JNI使用基本步骤
- Java中JDBC的基本步骤
- hessian远程调用及spring中使用hessian
- java中简述使用JDBC完成数据库操作的基本步骤。
- 使用Hessian和Burlap发布远程接口服务步骤
- Hessian远程调用框架进阶教程(一) Hessian介绍JAVA使用Hessian进行编程实例
- 在Spring中使用Hessian Remoting技术。
- 在Spring中使用Hessian Remoting技术
- 在Spring中使用Hessian Remoting技
- Spring中使用Hessian暴露服务
- (C++)智能指针的小“自传”
- 反走样技术
- Unity3D 封装WWW
- CentOS7 安装 Kibana
- 抽屉视图控制器的使用
- java中使用Hessian基本步骤
- webdriver之Can not connect to the Service chromedriver
- JVM自带性能分析工具介绍——jmap和jhat
- mySQL之视图、触发器、事务、存储过程、函数、流程控制
- Linux:安装jdk(tar)
- python-----奇怪的国家
- SylixOS周期定时抖动分析
- Spring加载properties文件的两种方式
- jsp+servlet实现文件的上传功能