import javax.jws.WebService;
/**
* Java6开发的WebService服务端
*
* @author leizhimin 2009-11-16 10:24:13
*/
@WebService
public class Java6WS {
/**
* Web服务中的业务方法
*
* @return 一个字符串
*/
public String doSomething(String username) {
return username + " is doing something!";
}
}
import lavasoft.server.Java6WS;
import javax.servlet.*;
import javax.xml.ws.Endpoint;
import java.io.IOException;
/**
* 发布Java6 WebService的Servlet,
*
* @author leizhimin 2009-11-16 13:52:49
*/
public class WSServlet extends GenericServlet {
@Override
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
System.out.println("准备启动WebService服务:http://192.168.14.117:8888/java6ws/Java6WS");
//发布一个WebService
Endpoint.publish("http://192.168.14.117:8888/java6ws/Java6WS", new Java6WS());
System.out.println("已成功启动WebService服务:http://192.168.14.117:8888/java6ws/Java6WS");
}
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println("此Servlet不处理任何业务逻辑,仅仅yonglai发布一个Web服务:http://192.168.14.117:8888/java6ws/Java6WS");
}
}
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>WSServlet</servlet-name>
<servlet-class>lavasoft.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WSServlet</servlet-name>
<url-pattern>/servlet/WSServlet</url-pattern>
</servlet-mapping>
</web-app>