使用xfire+spring编写webservice例子
来源:互联网 发布:墨泥学车模拟软件 编辑:程序博客网 时间:2024/04/28 02:26
利用xfire编写webservice的例子,内容如下
1. xfire + spring 发布webservice
2. 利用 javascript 调用发布的webservice
使用xfire+spring发布webservice其实很简单,遵循一下几个步骤即可
1. 想要发布成文webservice的类,必须实现接口
2. 3个配置文件(后面详细说)
下面针对以上步骤详细说明
关于1中的要求,给个例子就明白了
- package test;
- import org.json.JSONException;
- public interface IHello
- {
- public String hello();
- public String helloTo(String name);
- public String getJsonData(String pageIndex,String pageSize);
- }
- package test;
- import java.util.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpSession;
- import org.codehaus.xfire.transport.http.XFireServletController;
- import org.json.JSONException;
- import org.json.JSONStringer;
- public class HelloImpl implements IHello
- {
- public String hello()
- {
- return "hello";
- }
- public String helloTo(String name)
- {
- return " hello " + name + "!";
- }
- private void example()
- {
- //使用session
- HttpServletRequest request = XFireServletController.getRequest();
- HttpSession session = request.getSession();
- }
- public String getJsonData(String pageIndex,String pageSize)
- {
- String rtnValue = "";
- rtnValue = "";
- for(int i=0;i
- {
- rtnValue = rtnValue + "{'lastname': 'last" + pageIndex + "-" + i + "', 'firstname': 'first" + pageIndex + "-" + i + "' },";
- }
- rtnValue = rtnValue + "{'lastname': 'last', 'firstname': 'last' }";
- rtnValue = "{'context':[" + rtnValue + "],'pager':[{'totalRecord':'100','totalpage':'10','pageIndex':'" + pageIndex + "','pageSize':'10'}]}";
- return rtnValue;
- }
- }
就这样写就可以了
关于三个配置文件
web.xml修改如下
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <!-- 配置文件路径 开始 -->
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>/WEB-INF/classes/log4j.properties</param-value>
- </context-param>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- /WEB-INF/classes/applicationContext*.xml
- classpath:org/codehaus/xfire/spring/xfire.xml
- </param-value>
- </context-param>
- <!-- 启动时加载SpringContextServlet -->
- <listener>
- <listener-class>
- org.springframework.web.context.ContextLoaderListener
- </listener-class>
- </listener>
- <listener>
- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
- </listener>
- <listener>
- <listener-class>
- org.springframework.web.util.IntrospectorCleanupListener
- </listener-class>
- </listener>
- <!-- XFire 配置 -->
- <servlet>
- <servlet-name>xfire</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>xfire</servlet-name>
- <url-pattern>*.ws</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- </welcome-file-list>
- </web-app>
这里注意 classpath:org/codehaus/xfire/spring/xfire.xml 必须要写进去
xfire-servlet.xml 新建这个文件,并且和web.xml放在同一个文件夹
注意: 名称和位置都不能变(也许可以改,我不知道)
spring 的配置文件 applicationContext-webService.xml
- 使用xfire+spring编写webservice例子
- 使用xfire+spring编写webservice例子
- 使用xfire+spring编写webservice例子
- XFire + Spring 编写webservice
- 利用xfire编写webservice的例子
- 使用Spring+Xfire构建WebService
- 使用XFire开发WebService的简单例子
- 图文并茂——使用xfire编写webservice
- 使用xFire和Spring构建WebService
- xfire+spring webservice 配置
- xfire+spring整合webservice
- spring+xfire发布webservice
- spring xfire webservice
- spring+xfire开发webservice
- 使用xfire编写webservice,并通过C#调用
- spring-xfire简单例子
- 基于xFire的webService例子
- 使用xfire建立webservice
- 《JAVA编程思想》第四版学习 需要我记住的something –持有对象
- spring和3大动态语言(jruby groovy beanshell)的例子
- spring利用javamail,quartz定时发送邮件
- 微软实习生考核(1)
- 正则表达式引擎
- 使用xfire+spring编写webservice例子
- 获取进程的开始、结束时间
- JPA学习笔记
- 监视工具的过滤功能
- STUDY
- Symbian S60开发环境搭建
- Spring+JPA+MySQL的配置文件
- 等侍那一天的成功者
- 马云