8,906
社区成员
发帖
与我相关
我的任务
分享
package whao.test.hessian.official.server;
public interface BasicAPI {
public String hello();
}
package whao.test.hessian.official.server.impl;
import whao.test.hessian.official.server.BasicAPI;
import com.caucho.hessian.server.HessianServlet;
public class BasicService extends HessianServlet implements BasicAPI {
private String _greeting = "Hello, world";
public void set_greeting(String greeting) {
_greeting = greeting;
}
public String hello() {
// TODO Auto-generated method stub
return _greeting;
}
}
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-class</param-name>
<param-value>whao.test.hessian.official.server.impl.BasicService</param-value>
</init-param>
<init-param>
<param-name>home-api</param-name>
<param-value>whao.test.hessian.official.server.BasicAPI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<url-pattern>/hello</url-pattern>
<servlet-name>hello</servlet-name>
</servlet-mapping>
import java.net.MalformedURLException;
import whao.test.hessian.official.server.BasicAPI;
import com.caucho.hessian.client.HessianProxyFactory;
public class Test {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
//为什么使用HTTP访问不行
String url = "http://localhost:8089/hessian/hello";
HessianProxyFactory factory = new HessianProxyFactory();
BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class, url);
System.out.println("Hello: " + basic.hello());//结果是Hello: Hello, world 成功了
}
}