<html><body> <p>start</p> <jsp:useBean id="tAdder" scope="page" class="addition.Adder" /> <p>effectively this applies setFirst(27) to tAdder<p> <jsp:setProperty name="tAdder" property="first" value="27" /> <p>effectively this applies setSecond(42) to tAdder<p> <jsp:setProperty name="tAdder" property="second" value="42" /> <p> now apply getSum to tAdder </p> <p>sum is <jsp:getProperty name="tAdder" property="sum" /> </p> <p>effectively this applies setFirst(5) to tAdder<p> <jsp:setProperty name="tAdder" property="first" value="5" /> <p> now apply getSum to tAdder again </p> <p>sum is <jsp:getProperty name="tAdder" property="sum" /> </p> <p>finish</p> </body></html>
package addition; public class Adder { private String iX = "0"; private String iY = "0"; public void setFirst(String pFirst) { iX = pFirst; } public void setSecond(String pSecond) { iY = pSecond; } public String getSecond() { return iY; } public String getSum() { int tResult = Integer.parseInt(iX) + Integer.parseInt(iY); return "" + tResult; } }