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.
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:
Define an interface
Interface implementation class
Register Hessian service in web.xml
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.
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)
Client interface
Realizes the client to call the server service
Steps: 1. Create a Hessian agent factory.
2. Generate proxy class, parameters: interface class, interface address exposed by server Hessian
3. Call method
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.