时间:2021-07-01 10:21:17 帮助过:17人阅读
public interface ServiceI { public String say(String name); public Errors showError(String info); }
public class FirstService implements ServiceI{ @Override public String say(String name) { String res = "Hello, "+name+" from PHPRPC"; return res; } public Errors showError(String info){ Errors er = null; er = new Errors(); er.setId("1111"); er.setMsg("phprpc make error:"+info); return er; } }
public class Errors implements Serializable{ private String id; private String msg; public Errors(){} public String getId() { return id; } public void setId(String id) { this.id = id; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } }
public class PhprpcGloabService extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { [b]PHPRPC_Server server = new PHPRPC_Server(); FirstService first = new FirstService(); server.add(first); server.start(req, res);[/b] } }
GloabService com.smartcoms.service.PhprpcGloabService 1 GloabService /rpcservice/*
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="org.phprpc.*" %> <%@ page import="com.smartcoms.web.UIElement.Errors" %> <%@ page import="com.smartcoms.service.ServiceI" %>Phprpc 调试 <% PHPRPC_Client client = new PHPRPC_Client("http://localhost:8082/smartcoms/rpcservice/GloabService"); ServiceI service = (ServiceI)client.useService(ServiceI.class); out.println(service.say("中国")); Errors er = service.showError("信息"); out.println(er.getId()); out.println(er.getMsg()); %>