Logic greaterEqual Tag (... )

Empty tag -if the requested variable is greater than or equal to the specified value then this tag is used to evaluate the contents contained in the nested body parts of this tag.

Logic greaterEqual Tag (... )

Logic greaterEqual Tag (<logic: greaterEqual>...</logic:greaterThan>) 

     

empty tag - if the requested variable is greater than or equal to the specified value then this tag is used to evaluate the contents contained in the nested body parts of this tag.

This tag compares the variable against the specified constant value. If the variable is greater than or equal to the specified value then the nested body contents of this tag is evaluated

Attributes of greaterEqual Tag

Attribute Name Description
cookie

The variable contains  the cookie value needed to compare .Here the name is specified by this attribute.

header

The variable contains the header value needed to compare whose name is specified by this attribute. The name match is performed in a case insensitive manner.

name

The variable to be compared is the JSP bean specified by this attribute, if property is not specified, or the value of the specified property of this bean, if property is specified.

parameter

The variable to be compared is the first, or only, value of the request parameter specified by this attribute.

property

The variable contains  the bean property value needed to compare ,it is specified by this attribute. The property reference can be simple, nested, and/or indexed.

scope

This specifies the bean scope within which  the bean is searched  by the name property, or "any scope" if not specified.

value

The constant value is specified by other attribute(s) of this tag, needed to compare

Logic greaterThan Tag (<logic: greaterThan>...
</ logic:greaterThan>) 

greaterThan Tag : Tag evaluation of the nested body content occurs only if the specified value is greater than the specified value.

This tag compares the variable against the specified constant value. If the variable is greater than  the specified value then the nested body contents of this tag is evaluated

Attributes of greaterThan Tag

Attribute Name Description
cookie

The variable contains  the cookie value needed to compare .Here the name is specified by this attribute.

header

The variable contains the header value needed to compare whose name is specified by this attribute. The name match is performed in a case insensitive manner.

name

The variable to be compared is the JSP bean specified by this attribute, if property is not specified, or the value of the specified property of this bean, if property is specified.

parameter

The variable to be compared is the first, or only, value of the request parameter specified by this attribute.

property

The variable contains  the bean property value needed to compare ,it is specified by this attribute. The property reference can be simple, nested, and/or indexed.

scope

This specifies the bean scope within which  the bean is searched  by the name property, or "any scope" if not specified.

value

The constant value is specified by other attribute(s) of this tag, needed to compare

Example Illustrating the use of the Logic greaterEqual Tag<logic:greaterEqual> and the Logic greaterThan Tag<logic:greaterThan> .

Here you will learn to use the Struts  Logic tags. We will cover an example that will show  a comparison between  the two logic tags (ie..<;logic:greaterEqual> and the <logic:greaterThan>).

Example code

Creating an Action  Class

Develop a simple action class LogicAction.java.

package roseindia.net;

import java.io.*;
import java.util.*;

/**

* @author Amit Gupta
* @Web http://www.roseindia.net
* @Email [email protected]

**/
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import org.apache.struts.action.*;

public class LogicAction extends Action 
{
  public ActionForward execute(ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response)
  throws IOException, ServletException {

  

  return mapping.findForward("success");
  }
}

Creating Form Bean

Our form bean class contains only one property number. Here is the code of FormBean (LogicForm.java)

package roseindia.net;

import org.apache.struts.action.*;

/**

* @author Amit Gupta
* @Web http://www.roseindia.net
* @Email [email protected]

**/

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LogicForm extends ActionForm 
{
  
  private long number;  
  public 
long getNumber() 
  {
  return number;
  }
  
  public void setNumber(long number) 
  {
  this.number=number;
  }
 
  
  
  
}

Defining form Bean in struts-config.xml file

Add the following entry in the struts-config.xml file for defining the form bean

<form-bean name="LogicForm"  type="roseindia.net.LogicForm" />

 Developing the Action Mapping in the struts-config.xml

Here, Action mapping helps to select the method from the Action class for specific requests.
0

<action path="/LogicAction"
type="roseindia.net.LogicAction"
name="LogicForm"
scope="request"
input="/pages/InputLogic.jsp">
<forward name="success" path="/pages/output.jsp"/>
</action>

Developing the InputLogic.jsp page

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<html:html>
<head>
<title>Using &lt;logic&gt; Tags</title>
</head>

<body>
<h1>Using &lt;logic&gt; Tags</h1>

<html:form action="/LogicAction" method ="post">

<h2>Enter a number:</h2>
<html:text property="number"/>

<br>
<h3>The &lt;logic:greaterEqual&gt;tag works if you enter a value</h3>
<h3>greater than or equal to 1</h3>
<h3>The &lt;logic:greaterThan&gt;tag works if you enter a value</h3>
<h3>greater than to 10000</h3>
<br>

<html:submit value="Submit"/>


<html:cancel/>
</html:form>
</body>
</html:html>

Developing the output.jsp page

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<HTML>
<HEAD>
<TITLE>Here's Your Data...</TITLE>
</HEAD>

<BODY>
<H3>Here's Your Data...</H3>

<h4>The number entered is:

<bean:write name="LogicForm" property="number"/></h4>


<logic:greaterEqual name="LogicForm" property="number" value="1">
<h4>Using the tag&lt;logic:greaterEqual&gt;</h4> 
Result : greaterEqual
</logic:greaterEqual>



<logic:greaterThan name="LogicForm" property="number" value="10000">
<h4>Using the tag &lt;logic:greaterThan &gt; </h4> 
Result : greaterThan
</logic:greaterThan>


</BODY>
</HTML>

Add the following line in the index.jsp to call the form. 1

<li>
<html:link page="/pages/InputLogic.jsp">Struts File Upload</html:link>
<br>
Example demonstrates  how LogicAction Class works.
</li>

Building and Testing the Example 

To build and deploy the application go to Struts\Strutstutorial directory and type ant on the command prompt. This will deploy the application. Open the browser and navigate to the InputLogic.jsp page. Your browser displays the following  page. 2

Entering a number greater than 1 and less than 10000  to the InputLogic.jsp page evaluates the working of the <logic:greaterEqual> tag

It displays the following out.jsp page

Writing a number greater than 10000 to the InputLogic.jsp displays 3

The output.jsp displays the working of the both tags.