Java远程调用之Hessian篇简例

本文转自:http://hi.baidu.com/kingtoon%5Fgo/blog/item/d1b078c654759a1d9c163d64.html

Hessian官方主页:http://hessian.caucho.com/

代码部分按照个人习惯做微量改动,原作者莫怪,呵呵!

如下图所示新建工程:

Java远程调用之Hessian篇简例_第1张图片

代码如下:

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) { String url = "http://localhost:8080/Hessian/hessianService"; HessianProxyFactory factory = new HessianProxyFactory(); try { Hello hello = (Hello) factory.create(Hello.class, url); System.out.println(hello.hello("kingtoon")); } catch (MalformedURLException e) { e.printStackTrace(); } } }

HelloImpl.java

package server.impl; import server.Hello; public class HelloImpl implements Hello { public String hello(String name) { return "hello, " + name + "! Welcome to use Hessian."; } }

Hello.java

package server; public interface Hello { String hello(String name); }

web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>hessianService</servlet-name> <servlet-class> com.caucho.hessian.server.HessianServlet </servlet-class> <init-param> <param-name>service-class</param-name> <param-value>server.impl.HelloImpl</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>hessianService</servlet-name> <url-pattern>/hessianService</url-pattern> </servlet-mapping> </web-app>

所需jar包:本文使用hessian-3.2.1.jar,仅此而已。

其他资料:http://hi.baidu.com/hivemind/blog/item/3dfb1f2a20c9963b5243c121.html

你可能感兴趣的:(java,String,url,Class,interface,encoding)