In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use web service in JDK 6.0. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
First of all, let's take a look at web service,Java 6.0 in JDK 6.0, where JDK comes with a lightweight web service server. If you are more careful, you must find that there is sample code for Java webservice in the path where you installed Java.
I have developed web service with Java before, but I used an open source project called axis under apache. However, Java comes with its own, why bother to seek the distance. Today I will record the simplest Java webservice sample process I have created and share it with you.
I used Netbeans 6, and first set up a Java application project called WebServices. Set up a server program.
Package WebServices
Import javax.jws. *; import javax.xml.ws.Endpoint / * @ author hecm * / @ WebService (targetNamespace = "http://www.blogjava.net/JAVA-HE", serviceName = "HelloService") public class WSProvider {/ / @ WebResult (name = "Greetings") / / Custom the description of the method return value in WSDL @ WebMethod (action = "sayHi", operationName = "sayHi") public String sayHi (@ WebParam (name = "MyName") String name) {return "Hi "+ name / / @ WebParam is a custom parameter name related description in WSDL} @ Oneway / / indicates that the service method is one-way, with no return value and should not declare check exception @ WebMethod (action = "printSystemTime", operationName = "printSystemTime") / / customize the description public void printTime () {System.out.println (System.currentTimeMillis ()) related to the method in WSDL. } public static void main (String [] args) {Thread wsPublisher = new Thread (new WSPublisher ()); wsPublisher.start ();} private static class WSPublisher implements Runnable {public void run () {/ / publish WSProvider to the address of http: / / localhost:8888/hechangmin/WSProvider, you must call the wsgen command / / to generate the support class for the service class WSProvider, as follows: / / wsgen-class. WebServices.WSProvider Endpoint.publish ("http://localhost:8888/JAVA-HE/WSProvider", new WSProvider ());}
Needless to say, web service creates the corresponding package in JDK 6.0.
Then compile the file.
Go to the command prompt, go to the classes directory, and run: wsgen-cp. WebServices.WSProvider
You can see that several Java files and class files have been generated from the class just now.
What we need to do now is to release ws to http://localhost:8888/chinajash/WSProvider
The actual action is: Endpoint.publish ("http://localhost:8888/chinajash/WSProvider",new WSProvider ())"
Of course, run WSProvider directly.
Then enter http://localhost:8888/JAVA-HE/WSProvider?wsdl
You have already seen the generated wsdl (webservice description language).
That is, the server is OK.
Keep it running. Write a test client:
First select the project and right-click to create a new web service client. Enter the wsdl address you just generated for ws url:
Http://localhost:8888/JAVA-HE/WSProvider?wsdl
(actually: same effect as wsimport http://localhost:8888/JAVA-HE/WSProvider?wsdl)
Produce an effect: seven help class are generated under classes under the package (directory structure) generated according to the previously specified namespace.
Then we set up a package client to set up the test file:
/ * * To change this template, choose Tools | Templates * and open the template in the editor. * / package client; import net.blogjava.java_he. *; / * @ author hecm * / public class Test {public static void main (String args []) {HelloService hs = new HelloService (); WSProvider ws = hs.getWSProviderPort (); System.out.println (ws.sayHi ("hechangmin")); ws.printSystemTime ();}}
Run this test class:
Hi,hechangmin
Output.
This is the end of this article on "how to use web service in JDK 6.0". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.