日期:2014-05-18 浏览次数:20881 次
public static void main(String[] args) {
Store store = new Store();// 准备参数
// 首先创建一个webservice客户端,参数依次为:webservice的url, webservice的名称, webservice的方法, 参数列表, 返回类型, 泛型的类型(不需要泛型就传入null)
WebserviceClient client = new WebserviceClient("http://localhost:8088/TestWeb/webservice", "store", "find", new Object[] { store }, List.class, Store.class);
List<Store> list = client.execute();// 调用webservice
System.out.println("从服务器返回" + list.size() + "个商品");// 得到了服务端返回的数据
}
package com.wj.webservice;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.mvc.annotation.Webservice;
import org.apache.commons.mvc.annotation.WebserviceMethod;
import org.apache.commons.mvc.thread.HttpThread;
import com.wj.entity.Store;
import com.wj.model.StoreModel;
/**
* 发布商品的Webservice
* @version 1.0
*/
@Webservice(name = "store")
public class StoreWebservice {
/**
* 查询数据
* @param store
* @return
*/
@WebserviceMethod
public List<Store> find(Store store) {
HttpServletRequest request = HttpThread.getRequest();
System.out.println("request: " + request);
List<Store> list = new ArrayList<Store>();
return list;
}
}
<?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>wj</servlet-name>
<servlet-class>
org.apache.commons.mvc.webservice.WebserviceServlet
</servlet-class>
<init-param>
<param-name>package</param-name>
<param-value>com.wj.webservice</par