在上面給出的示例中,我們使用了基于控制臺(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)); %>