第1个回答 推荐于2016-06-18
用axis开发 很简单的主要就是一份wsdd文件
例如server-config.wsdd
Java代码
<service name="WebService" provider="java:RPC" style="rpc" use="encoded">
<parameter name="scope" value="Request"/>
<parameter name="className" value="com.dreamtech.webService.WebService"/><!-- 要发布的方法全在这个类里 -->
<parameter name="allowedMethods" value="*"/>
</service>
要发布的webService类的方法
Java代码
package com.dreamtech.webService;
import javax.xml.rpc.ServiceException;
import clients.WebServiceService;
import clients.WebServiceServiceLocator;
import clients.WebService_PortType;
import com.dreamtech.bo.Equipment;
import com.dreamtech.dao.Dao;
public class WebService {
//初次刷卡时 写入数据 并返回状态
public String save(String uId, String equipmentId){
String state = null;
Dao dao = Dao.getDaoInstance();
Equipment em = new Equipment();
em.setEquipmentId(equipmentId);
em.setUid(uId);
em.setState("0");
try {
dao.saveObject(em);
em = (Equipment)dao.findSingleObj("from Equipment e where e.uid='"+uId+"' and e.equipmentId='"+equipmentId+"'");
state = em.getState();
return state;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return "数据不存在,请联系管理员";
}
//离开时 更新数据 并返回状态
public String updateState(String uId, String equipmentId){
Dao dao = Dao.getDaoInstance();
String state = null;
Equipment em = new Equipment();
try {
em = (Equipment)dao.findSingleObj("from Equipment e where e.uid='"+uId+"' and e.equipmentId='"+equipmentId+"'");
em.setState("1");
dao.updateObject(em);
em = (Equipment)dao.findSingleObj("from Equipment e where e.uid='"+uId+"' and e.equipmentId='"+equipmentId+"'");
state = em.getState();
return state;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return "数据不存在,请联系管理员";
}
在web.xml里加入
Java代码
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AdminServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>本回答被提问者和网友采纳