没有合适的资源?快使用搜索试试~ 我知道了~
hession入门及注入spring
需积分: 32 11 下载量 8 浏览量
2012-05-03
10:17:34
上传
评论
收藏 129KB DOCX 举报
温馨提示
试读
19页
用hession完成远程调用或者将hession注入到spring中实现远程调用
资源推荐
资源详情
资源评论
13 hessian
入门教程
13.1 创建服务器端
导入 hessian 包
【第 1 步】编写服务器端接口 com.hessian.server.Hello.java
package com.hessian.server;
/**
* hessian 服务接口,用于客户端调用
* Hessian
建立的远程调用,是对服务的接口进行调用
*
* @author 莫小哆 _ly 2012-1-16
*/
public interface Hello {
/**
* 测试字符串
* @return
*/
public String sayHello();
}
【第 2 步】编写接口实现类 com.hessian.server.impl.HelloImpl.java
package com.hessian.server.impl;
import com.hessian.server.Hello;
/**
* 实现服务端接口
*
* @author 莫小哆 _ly 2012-1-16
*/
public class HelloImpl implements Hello {
private String hello = "Hello World";
@Override
public String sayHello() {
return hello;
}
//Getter/Setter
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
}
【第 3 步】修改配置文件 WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>hessianServer</display-name>
<!-- 用户键入的 URL 不包含 action 名称、JSP 页面或其他资源,依次寻找文件-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-
class>com.caucho.hessian.server.HessianServlet</servlet-class>
<init-param>
<param-name>home-api</param-name>
<param-value>com.hessian.server.Hello</param-value>
</init-param>
<init-param>
<param-name>home-class</param-name>
<param-value>com.hessian.server.impl.HelloImpl</param-
value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
【第 4 步】编写服务端的测试 jsp 页面 index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- 引入类-->
<%@ page import="java.util.*"%>
<%@ page import="com.caucho.hessian.client.HessianProxyFactory"%>
<%@ page import="com.hessian.server.Hello"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>hessian</title>
</head>
<body>
<%
// Hessian 代理工厂
HessianProxyFactory factory = new HessianProxyFactory();
// 控制台打印
System.out.println("test");
// jsp 页面打印
out.println("<h3>test</h3>");
//获得访问配置的 Servlet 路径
String url = ("http://" + request.getServerName() + ":" +
request.getServerPort()
+ request.getContextPath() + "/hello");
System.out.println(url);
out.println("request.getServerName() ==== " +
request.getServerName() + "<br/>");
out.println("request.getServerPort() ==== " +
request.getServerPort() + "<br/>");
out.println("request.getContextPath() ==== " +
request.getContextPath() + "<br/>");
//使用 Hessian 工厂获得接口的具体实现类
Hello hello = (Hello) factory.create(Hello.class, url);
out.println("<h2>" + hello.sayHello() + "<h2>");
%>
</body>
</html>
13.2 创建客户端
导入 hessian 包
【第 1 步】编写客户端接口 com.hessian.server.Hello.java
与服务器端保持一致
剩余18页未读,继续阅读
资源评论
朱天宇
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功