Spring通過(guò)HTTP調(diào)用程序進(jìn)行遠(yuǎn)程處理示例

基于Web的客戶端

在上面給出的示例中,我們使用了基于控制臺(tái)的客戶端。我們也可以使用基于Web的客戶端。您需要?jiǎng)?chuàng)建3個(gè)其他文件。在這里,我們使用以下文件:

ClientInvoker.java index.jsp process.jsp


ClientInvoker.java

它僅定義一種方法getCube(),該方法返回給定數(shù)量的多維數(shù)據(jù)集

package com.nhooo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ClientInvoker {
    public static int getCube(int number){
        ApplicationContext context = new ClassPathXmlApplicationContext("client-beans.xml");
        Calculation calculation = (Calculation)context.getBean("calculationBean");
        return calculation.cube(number);
    }
}

index.jsp

它創(chuàng)建一個(gè)獲取號(hào)碼的表格。

<form action="process.jsp">
Enter Number:<input type="text" name="number"/>
<input type="submit" value="cube" />
</form>

process.jsp

它創(chuàng)建一個(gè)獲取號(hào)碼的表格。

<jsp:include page="index.jsp"></jsp:include>
<hr/>
<%@page import="com.nhooo.ClientInvoker"%>
<%
int number=Integer.parseInt(request.getParameter("number"));
out.print("cube of "+number+" is: "+ClientInvoker.getCube(number));
%>

輸出

spring httpinvoker示例輸出1
spring httpinvoker示例輸出2

丰满人妻一级特黄a大片,午夜无码免费福利一级,欧美亚洲精品在线,国产婷婷成人久久Av免费高清