<Servlet> <servlet-Name> hessianservice </servlet-Name> <! -- Note that this is provided by Hessian --> <servlet-class> com. caucho. hessian. server. hessianservlet </servlet-class> <init-param> <param-Name> service-class </param-Name> <! -- Class called after instantiation --> <param-value> guilinsoft. ddsx. API. wdpfimpl </param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <Servlet -Name> hessianservice </servlet-Name> <URL-pattern>/hessianservice </url-pattern> </servlet-mapping>
Thanks.
The project needs to monitor the current status of the device in real time, and the server is remotely and so, and the powerful Hessian is found online. Haha, I always thought it was a session extension .. khan looked at its official website, a little dizzy, mainly because its configuration file was not clear, and then he found an instance shared by aliyunyou in oschina. oh, too .. if the call is successful, record it.
Simulate two projects, demo (server), client (client)
Greetingapi is the interface, while greetingservlet is the implementation of the interface... the name is not good ..
package example; public interface GreetingAPI { public String hello(); public String ok(); public String no();}package example; public class GreetingServlet implements GreetingAPI { private static final long serialVersionUID = 1L; private String _greeting="Hello,would!"; public String hello() { return _greeting; } public String ok(){ return "this is greetingServlet method ok!!"; } public void set_greeting(String greeting) { _greeting = greeting; } public String no() { return "this is greetingServlet method NO!!"; } }
Note that the package name must be the same as that of the server. Otherwise, an exception cannot be found in the instance. The content of greetingapi. Java is consistent with that of the server.
package example; import java.net.MalformedURLException; import com.caucho.hessian.client.HessianProxyFactory;import com.jzero.util.MPrint; public class test { public static void main(String[] args) { String url="http://localhost:8080/Demo/hessianService"; HessianProxyFactory factory=new HessianProxyFactory(); try { GreetingAPI api=(GreetingAPI) factory.create(url); MPrint.print(api.hello()); MPrint.print(api.ok()); MPrint.print(api.no()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
------- [Program debugging and printing data: Hello, wocould !] -------------- [Program debugging and printing data: This is greetingservlet method OK !!] -------------- [Program debugging and printing data: This is greetingservlet method no !!] -------
Source: Java remote Hessian call example
----------- Advertisement Area
Casual beans, it information, it news, BT download, HD download, Movie Download, single-host game download, game download, e-book download, and e-book PDF download