China Unicom project Article 3-servlet development client to call Web Service

Source: Internet
Author: User

Question 3: servlet development client calls Web Service

I didn't understand it at the beginning, but I don't know where to start. I first checked through the Internet how servlet called webservice. I found that servlet and webservice are a type of function and their functions are compared. Depressed. Then I asked my classmates, he said that half of them can automatically generate client code. I think I am using the cxf framework. Maybe the cxf framework can also automatically generate client code, So Baidu search, the method was found, so I followed the process and generated the client code. Then I joined the servlet project carefully and found that there were a lot of errors. However, the errors can be solved one by one (or directly deleted, ). If you do not know how to use servlet to call the service, you can view the generated client code, the client. java file, and find that it implements the simplest interface to call the webservice of the server, which is written by the imitator. You can call it slowly.

1. First, use the batch processing file wsdl2java. bat that comes with the cxf framework to generate the client code:

Run cmd → enter the binfile in the installation directory of cxf --> and enter the following command:

Wsdl2java-p com. zzzl. webservice (the package name of the client code to be generated)-d: \ cxfoutput \ src (the destination address where the generated client code is placed)-all http://game.qidian.com/RemoteWebService/IPreventIndulge? Wsdl (wsdl address)

Parameter description:

-P is the package corresponding to the package in java.

-D: Enter the directory where the. java file is generated and the package path configured with the-p parameter is automatically added.

-The client generates the code for the client to test the web service. -The server generates the code for the server to start the web service. -impl is used to generate the web service implementation code. -ant generate build. xml file. -all: generate all files corresponding to-client-server-impl-ant above. 2. Create a servlet project in the servlet project. You can directly call the interface functions exposed by webservice by referring to the code generated by the client. 3. The real implementation of page access involves jsp and ajax knowledge. It is a headache. I have never learned it. I can only refer to other people's code and modify it. Here there is web. xml configuration and parameter passing on the page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.