Home  >  Article  >  Java Servlet implements Hessian interface call

Java Servlet implements Hessian interface call

小云云
小云云Original
2017-11-04 13:29:072778browse

Java Servlet implements Hessian interface call

Java Servlet implements Hessian interface call

Hessian is a remote calling Http tool that provides the function of remote calling. Compared with WebService, hessian is simpler and faster. Hessian uses the binary RPC protocol for data transmission.

Under the premise of using Hessian, first of all, both the server and the client need to rely on the Hessian jar package.

Server side:

Customize an interface and implementation class of the interface on the server side.

Java Servlet implements Hessian interface call

I created a simple Java Web project locally, relying on jar packages: hessian-4.0.51.jar, javax.servlet-api-4.0.0.jar , you can download it from the Maven repository.

Written the interface and implementation class:

Java Servlet implements Hessian interface call

Define an interface

Java Servlet implements Hessian interface call

Interface implementation class

Register Hessian service in web.xml

Java Servlet implements Hessian interface call

Register Hessian service

Special attention here is home-api, home-class, yes The two parameters of the Hessian service, home-api corresponds to the interface, and home-class is the implementation class. The exposed interface is now complete and the Tomcat service is started.

Client:

Here I created a client project.

Java Servlet implements Hessian interface call

Client

If you want to call the server's service, you must create an interface that is exactly the same as the server's. (Remember! It must be exactly the same, and the method and class package name correspond)

Java Servlet implements Hessian interface call

Client interface

Realizes the client to call the server service

Java Servlet implements Hessian interface call

Steps: 1. Create a Hessian agent factory.

2. Generate proxy class, parameters: interface class, interface address exposed by server Hessian

3. Call method

Java Servlet implements Hessian interface call

Service The client has received the information from the client and has implemented the interface call

Is it very simple?

If you have any questions, you can exchange technology through comments in the area below.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn