Example of remotely calling PHPRPCforJava in java & nbsp; PHPRPC is a lightweight, secure, cross-Internet, cross-language, cross-platform, cross-environment, cross-domain, support for transmission of complex objects, support for parameter reference, and support example of remote calls to PHPRPC for java for content-output redirection, hierarchical error processing, session-oriented, and service-oriented high-performance Java
PHPRPC is a lightweight, secure, cross-Internet, cross-language, cross-platform, cross-environment, cross-domain, support for transmission of complex objects, support for parameter reference, and support high-performance remote process call protocol that supports content output redirection, hierarchical error processing, session-oriented, and service-oriented.
PHPRPC for Java needs to implement the client and server respectively. here is a specific example.
For example, the server is http: // localhost: 8080/server/, and the server is http: // localhost: 8080/client/
We need to build two projects: server and client. Then implement the client and server respectively.
1. server implementation:
1) create an implementation class:
Public class MyHello {
Public String say (String name ){
System. out. println ("hello world !! ");
Return "Hello" + name;
}
}
2) publish the service:
Create a new jsp named hello. jsp. the url is http: // localhost: 8080/server/hello. jsp.
Hello. jsp content:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<% @ Page import = "org. phprpc. PHPRPC_Server" %>
<% @ Page import = "test. MyHello" %>
<%
MyHello hello = new MyHello ();
PHPRPC_Server server = new PHPRPC_Server ();
Server. add (hello );
Server. start (request, response );
%>
In this way, it will be released.
2. client implementation:
1) define the interface, which corresponds to the server implementation class and is named Hello
Public interface Hello {
Public String say (String name );
}
2) after completing the preceding step, we can call it remotely to create a class named Test. java.
Public class Test {
Public static void main (String [] args ){
PHPRPC_Client client = new PHPRPC_Client ("http: // localhost: 8080/server/hello. jsp ");
Hello hello = (Hello) client. useService (Hello. class );
System. out. println (hello. say ("Java_KAbanban "));
}
When you run Test. java, you can achieve the desired result. the output is Hello Java_KAbanban.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.