(12) Web services combined with Javaweb (3)

Source: Internet
Author: User

First, the demand
    • The previous section, although binding WebService and Web projects together, does not share a single port, this chapter explains WebService and Web project bindings and common ports.

Ii. Case 2.1 Create a Web project and introduce a dependency

2.2 Authoring The Service interface
 Package Service; Import Javax.jws.WebParam; Import Javax.jws.WebResult; Import Javax.jws.WebService; @WebService (targetnamespace= "http://www/shyroke.com/")  Public Interface Ifirst {    = "Addresult")    publicintint int  y);}

2.3 Writing the service interface proxy class
 Package Service; Import Javax.jws.WebService; @WebService (endpointinterface= "service. Ifirst ")publicclassimplements  ifirst{    public  int Add (intint  y) {        return x+y;    }    }
2.4 Build and write Sun-jaxws.xml in the Web-inf directory
<?XML version = "1.0"?><Endpointsversion= "2.0"xmlns= "Http://java.sun.com/xml/ns/jax-ws/ri/runtime">    <Endpointname= "First"Implementation= "service. Firstdelegate "Url-pattern= "/firstport">    </Endpoint></Endpoints>

    • Where Url-pattern Browse the address of the Webserice service for the browser,implementation is the proxy class for the service interface

2.5 Configuring 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>    <Listener>        <Listener-class>Com.sun.xml.ws.transport.http.servlet.WSServletContextListener</Listener-class>    </Listener>    <servlet>        <Servlet-name>Public</Servlet-name>        <Servlet-class>Com.sun.xml.ws.transport.http.servlet.WSServlet</Servlet-class>        <Load-on-startup>1</Load-on-startup>    </servlet>    <servlet-mapping>        <Servlet-name>Public</Servlet-name>        <Url-pattern>/firstport</Url-pattern>    </servlet-mapping></Web-app>
2.6 Results

2.7 Finally build the client again

(12) Web services combined with Javaweb (3)

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.