Struts – <logic:greaterThan> <logic:greaterEqual> <logic:lessThan> <logic:lessEqual> example
Published: April 30, 2010 , Updated: April 27, 2010 , Author: mkyong
Download this example – Struts-Logic-Number-Condition-Tag-Example.zip
In Struts, four number condition tags are available…
- <logic:greaterThan> – check the given property is greater than the given value.
- <logic:greaterEqual> – check the given property is greater than or equal to the given value.
- <logic:lessThan> – check the given property is less than the given value.
- <logic:lessEqual> – check the given property is less than or equal to the given value.
If the condition is match, the body of the tag will be execute.
Here’s the example to show the use of the Struts <logic:greaterThan>, <logic:greaterEqual>, <logic:lessThan> and <logic:lessEqual>.
LogicExampleAction.java
package com.mkyong.common.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class LogicExampleAction extends Action{ public ActionForward execute(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { request.setAttribute("number", 100); return mapping.findForward("success"); } }
LogicExample.jsp
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> <html> <head> </head> <body> <h2>Struts - <logic:greaterThan></h2> <logic:greaterThan name="number" value="99"> <h3>Number 100 > 99 = true</h3> </logic:greaterThan> <h2>Struts - <logic:greaterEqual></h2> <logic:greaterEqual name="number" value="100"> <h3>Number 100 >= 100 = true</h3> </logic:greaterEqual> <h2>Struts - <logic:lessThan></h2> <logic:lessThan name="number" value="101"> <h3>Number 100 < 101 = true</h3> </logic:lessThan> <h2>Struts - <logic:lessEqual></h2> <logic:lessEqual name="number" value="100"> <h3>Number 100 <= 100 = true</h3> </logic:lessEqual> </body> </html>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd"> <struts-config> <action-mappings> <action path="/LogicTest" type="com.mkyong.common.action.LogicExampleAction"> <forward name="success" path="/pages/LogicExample.jsp"/> </action> </action-mappings> </struts-config>
Result
http://localhost:8080/StrutsExample/LogicTest.do

Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
[ Read More ] You can find more similar articles at Struts 1.x Tutorials