服务接口:
业务实现:
web.xml 配置信息:
客户端调用:
结果输出:
Hello, 美女
package com.test;
public interface TFSFacade {
String sayHello(String username);
}
业务实现:
package com.test;
public class TFSFacadeImpl implements TFSFacade {
public String sayHello(String username) {
return "Hello, " + username;
}
}
web.xml 配置信息:
<servlet>
<servlet-name>hessian</servlet-name>
<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-class</param-name>
<param-value>com.test.TFSFacadeImpl</param-value>
</init-param>
<init-param>
<param-name>home-api</param-name>
<param-value>com.test.TFSFacade</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>hessian</servlet-name>
<url-pattern>/hessian/tfs.xsp</url-pattern>
</servlet-mapping>
客户端调用:
package com.test;
import java.net.MalformedURLException;
import com.caucho.hessian.client.HessianProxyFactory;
public class Main {
/**
* @param args
* @throws MalformedURLException
*/
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
String target = "http://localhost:8080/TFS/hessian/tfs.xsp";
HessianProxyFactory factory = new HessianProxyFactory();
TFSFacade client = (TFSFacade) factory.create(TFSFacade.class, target);
System.out.println(client.sayHello("美女"));
}
}
结果输出:
Hello, 美女