English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Spring remote processing example through HTTP call program

a web-based client

In the example given above, we used a console-based client. We can also use a web-based client. You need to create3other files. Here, we use the following files:

ClientInvoker.java index.jsp process.jsp


ClientInvoker.java

It defines only one method getCube(), which returns a multidimensional dataset of the given number

package com.w3codebox;
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

It creates a table to get the number.

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

process.jsp

It creates a table to get the number.

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

Output