hessian_20130911

发布时间:2017-1-17 8:41:06 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"hessian_20130911",主要涉及到hessian_20130911方面的内容,对于hessian_20130911感兴趣的同学可以参考一下。

create web project EasyHession,put Hession.jar in web-inf/lib create interface package app.demo; public interface BasicAPI{ public void setGreeting(String greeting); public String hello(); public User getUser(); } implements interface package app.demo; public class BasicService implements BasicAPI {    private String _greeting = "Hello, world";    public void setGreeting(String greeting){       _greeting = greeting;       System.out.println("set greeting success:"+_greeting);    }    public String hello(){       return _greeting;    }    public User getUser() {       return new User("prance", "meshow");    } } create a pojo implements Serializable package app.demo; import java.io.Serializable; public class User implements Serializable{    String userName ="snoopy";    String password ="showme";    public User(Stringuser, String pwd) {       this.userName =user;       this.password= pwd;    }    public String getUserName() {       return userName;    }    public String getPassword() {       return password;    } } config web.xml <?xml version="1.0"encoding="UTF-8"?> <web-app version="2.4"    xmlns="http://java.sun.com/xml/ns/j2ee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet>    <servlet-name>hello</servlet-name>    <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>    <init-param>       <param-name>service-class</param-name>       <param-value>app.demo.BasicService</param-value>    </init-param> </servlet>    <servlet-mapping>       <servlet-name>hello</servlet-name>       <url-pattern>/hello</url-pattern>    </servlet-mapping> </web-app> test.jsp <%@ pageimport="com.caucho.hessian.client.HessianProxyFactory, app.demo.BasicAPI"%> <[email protected] language="java"%> <% HessianProxyFactory factory = newHessianProxyFactory(); String url = ("http://" +request.getServerName() + ":" +request.getServerPort() + request.getContextPath() + "/hello"); out.println(url); BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class,url); out.println("Hello: " + basic.hello()); out.println("Hello: " + basic.getUser() .getUserName() ); out.println("Hello: " +basic.getUser().getPassword() ); %> java client create java project HessianClient,import hessian.jar public interface BasicAPI{    public void setGreeting(String greeting);    public String hello();    public User getUser(); } import java.io.Serializable; public class User implements Serializable{    String userName ="snoopy";    String password ="showme";    public User(Stringuser, String pwd) {       this.userName =user;       this.password= pwd;    }    public String getUserName() {       return userName;    }    public String getPassword() {       return password;    } } importcom.caucho.hessian.client.HessianProxyFactory; public class BasicClient {    public static void main(String[] args) throws Exception{       String url ="http://127.0.0.1:8080/Hessian/hello";       HessianProxyFactory factory = new HessianProxyFactory();       BasicAPI basic = (BasicAPI) factory.create(BasicAPI.class, url);       System.out.println("Hello:" + basic.hello());       System.out.println("Hello:" + basic.getUser().getUserName());       System.out.println("Hello:" + basic.getUser().getPassword());       basic.setGreeting("HelloGreeting");       System.out.println("Hello:" + basic.hello());    } }

上一篇:C语言中的位域、字节序、比特序、大小端
下一篇:c++知识点总结

相关文章

关键词: hessian_20130911

相关评论