java hessian案例_Hessian快速入门案例

服务器端

工程目录结构

fad288cd73335955043943f0604d12b3.png

代码:

pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.hessiantest.client

hessianServer

0.0.1-SNAPSHOT

war

hessianServer

http://maven.apache.org

UTF-8

junit

junit

3.8.1

test

com.caucho

hessian

4.0.38

web.xml:

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

hello

com.caucho.hessian.server.HessianServlet

service-class

com.hessiantest.client.hessianServer.HelloServiceImpl

hello

/hello

然后把服务器端的war包部署到Tomcat,如图

7d1ee2af04e58261545dbc994317c885.png

Client端:

Client.java

服务器端请求类

HelloService.java

远程接口的存根

package com.hessiantest.client.hessianClient;

public interface HelloService

{

public String sayHello();

}

package com.hessiantest.client.hessianClient;

import java.net.MalformedURLException;

import com.caucho.hessian.client.HessianProxy;

import com.caucho.hessian.client.HessianProxyFactory;

import com.caucho.hessian.io.Hessian2Constants;

/**

* Hello world!

*

*/

public class Client

{

public static void main(String[] args) throws MalformedURLException, ClassNotFoundException

{

HessianProxyFactory factory = new HessianProxyFactory();

String url = "http://localhost:8080/hessianServer-0.0.1-SNAPSHOT/hello";

HelloService i = (HelloService)factory.create(HelloService.class,url);

System.out.println(i.sayHello());

}

}

邮件->run ,如图

09a09e9ee9367c16b40d5c8c783e0335.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值