Chinaunix首页 | 论坛 | 博客
  • 博客访问: 284173
  • 博文数量: 82
  • 博客积分: 2607
  • 博客等级: 少校
  • 技术积分: 785
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-14 15:23
文章分类

全部博文(82)

文章存档

2012年(4)

2010年(1)

2009年(2)

2008年(8)

2007年(34)

2006年(33)

我的朋友

分类: Java

2006-09-14 16:21:03

写一个JavaBean
import java.util.Hashtable;
import java.util.Vector;

public class RpcAuth {

    public String getVersion() {
        return "1.0";
    }

    public Hashtable getVersionInfo() {
        Hashtable result = new Hashtable();
        Hashtable result1 = new Hashtable();
        result1.put("my", "kdkkdkdkd");
        result.put("version", result1);
        result.put("build", "20060705");
       
        return result;
    }
   
    public Vector getVersionArray() {
        Vector result = new Vector();
       
        result.add("1.0");
        result.add("20060705");
       
        return result;
    }
}


这样一点一点自己改关键字的颜色好累呀,真是浪费时间,有没有高手给留了言
 谢谢 郁闷 试了N次了 只有自己写一个改颜色的程序了



再写一个Servlet这个是Apache-XMLRPC哟

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.xmlrpc.XmlRpcServer;

public class RpcServlet extends HttpServlet {

    public static final long serialVersionUID = 0;

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        XmlRpcServer xmlrpc = new XmlRpcServer();
         
       // 这是你自己的业务方法 供客户端使用的
        xmlrpc.addHandler("auth", new RpcAuth());

        byte[] result = xmlrpc.execute(request.getInputStream());
        System.out.println(new String(result));

        response.setContentType("text/xml");
        response.setContentLength(result.length);
        OutputStream out = response.getOutputStream();
        out.write(result);
        out.flush();
    }
}

下面配置的web.xml 这个是通用的都一样

    
XmlRpcServlet
org.apache.xmlrpc.webserver.XmlRpcServlet



XmlRpcServlet
/xmlrpc
服务器端就这个样子了 是不是太简单了 其实这个是Apache XML-RPC 我们只是使用
原理我在其它文章里再讲吧

阅读(1243) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~