Oh, yes. I have done it!!
I will write it here for you as Thanks and for you all.
Step by step
0> first you must have Tomcat-plugin in your eclipse
1>. Server-side-programm
1. File->new->other->java->
create a Tomcat-Project named "TomWs"->finish
2. in WEB-INF\src create
HelloServlet.java: a Servlet, the only duty is to publish the WS-endpoint onto a URL (hier is
Http://localhost:8080/services)
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.swing.JOptionPane;
import javax.xml.ws.Endpoint;
public class HelloServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
Endpoint endpoint = Endpoint.publish( "
http://localhost:8080/services",
new sayHello() );
res.setContentType( "text/html" );
PrintWriter out = res.getWriter();
out.println( "<html>" );
out.println( "Hallo, mein erstes Servlet meldet sich." );
out.println( "</html>" );
out.close();
JOptionPane.showMessageDialog( null, "Server beenden" );
endpoint.stop();
}
}
SayHello.java: a normal class, describes the Web-Service with Jax-Ws Annotation.
import javax.jws.soap.SOAPBinding;
import javax.jws.*;
@WebService(name="XinServ",targetNamespace="http:///")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class sayHello
{
@WebMethod
public String hello( String name )
{
return "Hello " + name + "!";
}
@WebMethod(operationName="body-mass-index")
@WebResult(name = "your-bmi")
public double bmi( @WebParam(name="height") double height,
@WebParam(name="weight") double weight )
{
return weight / (height * height) / 100 * 100;
}
}
3. compile the tow classes in Web-Inf\classes with the two commandos:
set classpath=C:\Tomcat\jakarta-tomcat-5.5.9\common\lib\servlet-api.jar
javac -d classes -sourcepath src src\HelloServlet.java
4. create web.xml in WEB-INF\web.xml
<!DOCTYPE web-app PUBLIC
'-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
'
http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>HelloServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
5. start Tomcat-server in eclipse
Repeat to compile the classes = reload them in Tomcat
6. in URL-Address input:
http://localhost:8080/TomWs/hello, It’s the address of the Servlet, that only tomcat automatic loads. In the browser will show “Hello….”, and there are small dialog "server beenden", don’t close it, then go on with input the
http://localhost:8080/services?wsdl. Wenn you can see this, you’re done!
7. leave the little widow open.
回复 更多评论