<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <h2>Interest Calculation </h2> <s:form action="interest"> <s:textfield name="amount" label="Principal Amount "/> <s:textfield name="rate" label="Interest Rate "/> <p/> <s:submit value="Calculate"/> </s:form> </body> </html>
package action; public class InterestAction { private double amount, rate, result; public double getResult() { return result; } public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } public double getRate() { return rate; } public void setRate(double rate) { this.rate = rate; } public InterestAction() { } public String execute() throws Exception { result = amount * rate / 100; return "success"; } }
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" extends="struts-default"> <action name="interest" class="action.InterestAction"> <result name="success">/result.jsp</result> </action> </package> </struts>
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <h2>Interest = <s:property value="result" /> </h2> </body> </html>