熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

Java遠程調用之Hessian簡例(2)

2022-06-13   來源: Java核心技術 

  代碼如下

  RomoteTestjava

  package client;

  import MalformedURLException;

  import serverHello;

  import comcauchohessianclientHessianProxyFactory;

  public class RomoteTest {

  public static void main(String[] args) {

  String url = //localhost:/Hessian/hessianService;

  HessianProxyFactory factory = new HessianProxyFactory();

  try {

  Hello hello = (Hello) factorycreate(Helloclass url);

  Systemoutprintln(hellohello(kingtoon));

  } catch (MalformedURLException e) {

  eprintStackTrace();

  }

  }

  }

  HelloImpljava

  package serverimpl;

  import serverHello;

  public class HelloImpl implements Hello {

  public String hello(String name) {

  return hello + name + ! Welcome to use Hessian;

  }

  }

  Hellojava

  package server;

  public interface Hello {

  String hello(String name);

  }

  webxml

  <?xml version= encoding=UTF?>

  <webapp version= xmlns=

  xmlns:xsi=instance

  xsi:schemaLocation=

  app__xsd>

  <servlet>

  <servletname>hessianService</servletname>

  <servletclass>

  comcauchohessianserverHessianServlet

  </servletclass>

  <initparam>

  <paramname>serviceclass</paramname>

  <paramvalue>serverimplHelloImpl</paramvalue>

  </initparam>

  <loadonstartup></loadonstartup>

  </servlet>

  <servletmapping>

  <servletname>hessianService</servletname>

  <urlpattern>/hessianService</urlpattern>

  </servletmapping>

  </webapp>

  所需jar包本文使用hessianjar僅此而已


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26209.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.