web.xml:
<servlet>
<servlet-name>testService</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-api</param-name>
<param-value>com.caucho.hessian.test.TestService</param-value>
</init-param>
<init-param>
<param-name>home-class</param-name>
<param-value>com.caucho.hessian.test.TestServiceImpl</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>testService</servlet-name>
<url-pattern>/testService</url-pattern>
</servlet-mapping>
java服务类:
public class TestServiceImpl implements TestService{
public String say(){
return "test:" + TestServiceImpl.class.getName();
}
public TestObject getTestObject(){
return new TestObject("123456");
}
}
public interface TestService {
String say();
TestObject getTestObject();
}
public class TestObject {
private Object _value;
客户端:
public class Main {
public static void main(String[] arg) throws Exception{
String urlString = "http://localhost/hessian/testService";
HessianProxyFactory factory = new HessianProxyFactory();
TestService testService = (TestService)factory.create(TestService.class,urlString);
System.out.println(testService.say());
System.out.println(testService.getTestObject());
}
}
本文介绍如何在Web应用中通过web.xml配置文件使用HessianServlet来实现Java服务类之间的远程调用,包括服务类的创建、配置及客户端调用过程。
900

被折叠的 条评论
为什么被折叠?



