Now, let us have a look how you need to do when using SoybeanMilk.
First, you must write a Java class, just like the following calculator example:
package my;
public class Calculator
{
public int multiply(int a, int b)
{
return a*b;
}
public int add(int a, int b)
{
return a+b;
}
}
Next, add the following configuration file named "soybean-milk.config.xml" to "/WEB-INF" folder:
<?xml version="1.0" encoding="UTF-8"?>
<soybean-milk>
<resolvers>
<resolver id="calculator" class="my.Calculator" />
</resolvers>
<executables>
<action name="/calculate.do">
<invoke>
multiplyResult = calculator.multiply(param.a, 10);
</invoke>
<invoke>
calculateResult = calculator.add(request.multiplyResult, 10)
</invoke>
<!--or you can use XML mode like this
<invoke method="multiply" resolver="calculator" result-key="multiplyResult">
<arg>param.a</arg>
<arg>10</arg>
</invoke>
<invoke method="add" resolver="calculator" result-key="calculateResult">
<arg>request.multiplyResult</arg>
<arg>10</arg>
</invoke>
-->
<target url="/calculate_result.jsp" />
</action>
</executables>
</soybean-milk>
Then, write the view page named "/calculate_result.jsp":
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Calculate</title>
</head>
<body>
Calculate: ${calculateResult}
</body>
</html>
And add the following XML codes to your "web.xml":
<servlet>
<servlet-name>dispatchServlet</servlet-name>
<servlet-class>org.soybeanMilk.web.servlet.DispatchServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatchServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Put SoybeanMilk and it's dependent library
soybeanMilk-[version].jar commons-beanutils-1.8.2.jar commons-logging-1.0.4.jar commons-logging-api-1.1.jar log4j-1.2.14.jar (Optional)into "/WEB-INF/lib" folder.
That's OK!
Now, start the web server, and type "http://[youApp]/calculate.do?a=3" in your internet explorer,
you will see "Calculate: 40".