1. [代码]1.服务接口(Hello.java)
package server;
public interface Hello {
String hello(String name);
}
2. [代码]2.接口实现(HelloImpl.java)
package server;
public class HelloImpl implements Hello{
public String hello(String name) {
return "hello,"+name+"! 欢迎学习Hessian";
}
}
3. [代码]服务端配置(web.xml)
xmlns=""
xmlns:xsi=""
xsi:schemaLocation="
/web-app_2_4.xsd">
hessianService
com.caucho.hessian.server.HessianServlet
service-class
server.HelloImpl
1
hessianService
/hessianService
4. [代码]4.客户端代码(RomoteTest.java)
package client;
import java.net.MalformedURLException;
import server.Hello;
import com.caucho.hessian.client.HessianProxyFactory;
public class RomoteTest {
public static void main(String[] args) {
//hessian服务的url 其中hessian-v1是项目名
String url = "";
//创建HessianProxyFactory实例
HessianProxyFactory factory = new HessianProxyFactory();
//获得Hessian服务的远程引用
try {
Hello hello = (Hello)factory.create(Hello.class,url);
System.out.println(hello.hello("kingtoon"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
阅读(725) | 评论(0) | 转发(0) |