1.下载jar包
http://hessian.caucho.com/
2.配置web.xml
<servlet>
<servlet-name>HelloServlet</servlet-name>
<!-- hession 提供的servlet -->
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-class</param-name>
<param-value>com.asarja.hessian.HelloImpl</param-value>
</init-param>
<init-param>
<param-name>home-api</param-name>
<param-value>com.asarja.hessian.IHello</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloServlet</url-pattern>
</servlet-mapping>
3.创建接口和实现类,服务器端和客户端使用相同的接口
public interface IHello {
String sayHello();
}
public class HelloImpl implements IHello{
public String sayHello() {
return "hello hession!";
}
}
4.测试
public class Test {
public static void main(String[] args) throws HessianProtocolException {
String url = "http://127.0.0.1:8080/hessian/helloServlet";
HessianProxyFactory hessianProxyFactory = new HessianProxyFactory();
try {
IHello iHello;
iHello = (IHello)hessianProxyFactory.create(IHello.class,url);
System.out.println("result="+iHello.sayHello());
} catch (MalformedURLException e){
e.printStackTrace();
} catch (HessianRuntimeException e){
e.printStackTrace();
}
}
}
使用hessian,客户端远程调用服务器端