Showing posts with label Struts Logic Tags Examples. Show all posts
Showing posts with label Struts Logic Tags Examples. Show all posts

Logic Present Tag (...)

present tag -This tag evaluates its nested body contents if the specified value is present in the request.

This tag checks the current request and depending on which attribute is specified, it evaluates the nested body content of this tag only if the specified value is present.

Attributes of Present Tag

Attribute Name Description
cookie

It checks the existence of a cookie with the specified name.

header

It checks the existence of an HTTP header with the specified name. The name match is performed in a case insensitive manner.

name

It checks the existence of a JSP bean, in any scope, with the specified name. If property is also specified, checks for a non-null property value for the specified property.

parameter

It checks the existence of at least one occurrence of the specified request parameter on this request, even if the parameter value is a zero-length string.

property

It checks the existence of a non-null property value, returned by a property getter method on the JSP bean (in any scope) that is specified by the name attribute. Property references can be simple, nested, and/or indexed.

role

It checks whether the currently authenticated user (if any) has been associated with any of the specified security roles. Use a comma-delimited list to check for multiple roles.

scope

The bean scope within which to search for the bean named by the name property, or "any scope" if not specified.

user

It checks whether the currently authenticated user principal has the specified name.

Logic notPresent Tag (...)

notPresent tag -This tag evaluates its nested body content if the specified value is not present in the request.

Tag evaluation of the nested body content occurs only if the specified value is not available in the request i.e... works in reverses to present tag.

Attributes of notPresent Tag

Attribute Name Description
cookie

It checks the existence of a cookie with the specified name.

header

It checks the existence of an HTTP header with the specified name. The name match is performed in a case insensitive manner.

name

It checks the existence of a JSP bean, in any scope, with the specified name. If property is also specified, checks for a non-null property value for the specified property.

parameter

It checks the existence of at least one occurrence of the specified request parameter on this request, even if the parameter value is a zero-length string.

property

It checks the existence of a non-null property value, returned by a property getter method on the JSP bean (in any scope) that is specified by the name attribute. Property references can be simple, nested, and/or indexed.

role

It checks whether the currently authenticated user (if any) has been associated with the specified security role.

scope

The bean scope within which to search for the bean named by the name property, or "any scope" if not specified.

user

It checks whether the currently authenticated user principal has the specified name.

Example Illustrating the use of the present and the notPresent logic tags.

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.. and the ).

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 struts@roseindia.net

**/
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 text. 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 struts@roseindia.net

**/

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

public class EmptyForm extends ActionForm
{

private String text = "";

public String getText()
{
return text;
}

public void setText(String text)
{
this.text=text;
}




}

Defining form Bean in struts-config.xml file

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

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.



Developing the InputLogic.jsp page

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


Using <logic> Tags



Using <logic> Tags





Enter text :









Developing the output.jsp page:

Notice the property values

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



Here's Your Data...


Here's Your Data...



The text entered is:



property="text" >
Using the tag <logic:present >

Result: Successfully supported

property="text1" >

Using the tag<logic:notPresent>

Result: Support for a Variable other than a String is not Present



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


  • Struts File Upload


    Example demonstrates how LogicAction Class works.

  • 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.

    Writing a text string to the InputLogic.jsp page lets you to see the working of the present Logic tag and the notPresent Logic tag .

    It displays the following out.jsp page

    read more “Logic Present Tag (...)”

    Logic Match Tag (...)

    match tag - We use this tag to evaluate the contents contained in the nested body parts of this tag if the specified value is an appropriate substring of the requested variable.

    This tag matches the variable specified as a String against the specified constant value. If the value is a substring then the nested body content of this tag is evaluated.

    Attributes of match Tag

    Attribute Name Description
    cookie

    The variable to be matched is the value of the cookie whose name is specified by this attribute.

    header

    The variable to be matched is the value of the header whose name is specified by this attribute. The name match is performed in a case insensitive manner.

    location

    If not specified, a match between the variable and the value may occur at any position within the variable string. If specified, the match must occur at the specified location (either start or end) of the variable string.

    name

    The variable to be matched 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 matched is the first, or only, value of the request parameter specified by this attribute.

    property

    The variable to be matched is the property (of the bean specified by the name attribute) specified by this attribute. The property reference can be simple, nested, and/or indexed.

    scope

    The bean scope within which to search for the bean named by the name property, or "any scope" if not specified.

    value

    The constant value which is checked for existence as a substring of the specified variable.

    Logic notMatch Tag (...)

    notMatch - We use this tag to evaluate the contents contained in the nested body parts of this tag if the specified value is not a substring of the requested variable.

    This tag matches the variable specified by one of attributes (as a String) against the specified constant value. If the value is not a substring the nested body content of this tag is evaluated.


    Attributes of notMatch Tag

    Attribute Name Description
    cookie

    The variable to be matched is the value of the cookie whose name is specified by this attribute.

    header

    The variable to be matched is the value of the header whose name is specified by this attribute. The name match is performed in a case insensitive manner.

    location

    If not specified, a match between the variable and the value may occur at any position within the variable string. If specified, the match must occur at the specified location (either start or end) of the variable string.

    name

    The variable to be matched 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 matched is the first, or only, value of the request parameter specified by this attribute.

    property

    The variable to be matched is the property (of the bean specified by the name attribute) specified by this attribute. The property reference can be simple, nested, and/or indexed.

    scope

    The bean scope within which to search for the bean named by the name property, or "any scope" if not specified.

    value

    The constant value which is checked for existence as a substring of the specified variable.

    Example Illustrating the use of the Match and the notMatch logic tags.

    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.. and the ).

    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 struts@roseindia.net

    **/
    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 text. 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 struts@roseindia.net

    **/

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

    public class EmptyForm extends ActionForm
    {

    private String text = "";

    public String getText()
    {
    return text;
    }

    public void setText(String text)
    {
    this.text=text;
    }




    }

    Defining form Bean in struts-config.xml file

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

    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.



    Developing the InputLogic.jsp page

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



    Using <logic> Tags



    Using <logic> Tags





    Enter text:






    The <logic:match>tag works if the entered


    text contains "amit"


    The <logic:notMatch>tag always evaluate the


    entered text against the"abc" value











    Developing the output.jsp page

    Notice the values

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



    Here's Your Data...



    Here's Your Data...



    The text entered is:




    match name="LogicForm" property="text" value="amit">
    Using the tag <logic:match >

    Result : entered text contains "amit"
    match>



    :notMatch name="LogicForm" property="text" value="abc">
    Using the tag<logic:notMatch>

    Result: entered text does not contains "abc"
    notMatch>


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


  • Struts File Upload


    Example demonstrates how LogicAction Class works.

  • 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.

    Writing text including "amit" and excluding "abc" to the InputLogic.jsp page displays the working of the match Logic tag and the notMatch Logic tag .

    It displays the following to the out.jsp page

    Writing text including "amit" and "abc" to the InputLogic.jsp page displays the working of the match Logic tag and the notMatch Logic tag .

    The evaluated here displays the output.jsp as

    read more “Logic Match Tag (...)”

    Logic LessEqual Tag (...)

    lessEqual Tag - If the requested variable is either less or equal to the specified values then we use this tag 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 less than or equal to the specified value then the nested body contents of this tag is evaluated

    Attributes of lessEqual 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 LessThan Tag (...)

    lessThan Tag- If the requested variable is less than the specified values then we use this tag 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 less than the specified value then the nested body contents of this tag is evaluated

    Attributes of lessThan 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 lessEqual and the lessThan logic tags.

    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.. and the ).

    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 struts@roseindia.net

    **/
    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 struts@roseindia.net

    **/

    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

    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.



    Developing the InputLogic.jsp page

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



    Using <logic> Tags



    Using <logic> Tags





    Enter a number:






    The <logic:lessEqual>tag works if you enter a value


    less than or equal to 100


    The <logic:lessThan>tag works if you enter a value


    less than to 10000












    Developing the output.jsp page

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



    Here's Your Data...



    Here's Your Data...



    The number entered is:




    lessEqual name="LogicForm" property="number" value="100">

    Using the tag<logic:lessEqual>


    Result : lessEqual
    lessEqual>


    :lessThan name="LogicForm" property="number" value="10000">

    Using the tag <logic:lessThan >


    Result : lessThan
    lessThan>



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


  • Struts File Upload


    Example demonstrates how LogicAction Class works.

  • 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.

    Writing a number equal to 101 to the InputLogic.jsp page displays the working of the lessThan Logic tag

    It displays the following out.jsp page

    Now write data equal 100 to the InputLogic.jsp to compare the working of the lessEqual and lessThan tags

    Here both tags are evaluated it displays the output.jsp as

    read more “Logic LessEqual 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.

    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 (...
    )

    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 and the Logic greaterThan Tag .

    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 ).

    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 struts@roseindia.net

    **/
    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 struts@roseindia.net

    **/

    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

    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.



    Developing the InputLogic.jsp page

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



    Using <logic> Tags



    Using <logic> Tags





    Enter a number:






    The <logic:greaterEqual>tag works if you enter a value


    greater than or equal to 1


    The <logic:greaterThan>tag works if you enter a value


    greater than to 10000












    Developing the output.jsp page

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



    Here's Your Data...



    Here's Your Data...



    The number entered is:




    greaterEqual name="LogicForm" property="number" value="1">

    Using the tag<logic:greaterEqual>


    Result : greaterEqual
    greaterEqual>



    greaterThan name="LogicForm" property="number" value="10000">

    Using the tag <logic:greaterThan >


    Result : greaterThan
    greaterThan>



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


  • Struts File Upload


    Example demonstrates how LogicAction Class works.

  • 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.

    Entering a number greater than 1 and less than 10000 to the InputLogic.jsp page evaluates the working of the tag

    It displays the following out.jsp page

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

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

    read more “ ”

    Logic Equal Tag (...)

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

    Compares the variable passed against the specified constant value. The nested body content of this tag is evaluated if the variable and value are equal.

    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 notEqual Tag (...)

    notEmpty - if the requested variable is not equal to the specified value then this tag is used to evaluate the contents contained in the nested body parts of this tag.

    Compares the variable passed against the specified constant value. The nested body content of this tag is evaluated if the variable and value are not equal.

    Attributes of notEmpty 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 Equal and the notEqual logic tags.

    Here you will learn to use the Struts Logic Equal and notEqual tags. We will cover an example that will show a comparison between the two logic tags (ie.. and the ).

    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 struts@roseindia.net

    **/
    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 struts@roseindia.net

    **/

    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

    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.



    Developing the InputLogic.jsp page

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



    Using <logic> Tags



    Using <logic> Tags





    Enter a number:






    The <logic:Equal>tag works if you enter 1



    else The <logic:notEqual> is processed













    Developing the output.jsp page

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



    Here's Your Data...



    Here's Your Data...



    The number entered is:



    equal name="LogicForm" property="number" value="1">

    Using the tag <logic:equal >


    Result : Equal
    equal>

    notEqual name="LogicForm" property="number" value="1">

    Using the tag <logic:notEqual >


    Result : notEqual
    notEqual>



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


  • Struts File Upload


    Example demonstrates how LogicAction Class works.

  • 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.

    Writing value equal to1 to the InputLogic.jsp page displays the working of the Equal Logic tag

    It displays the following out.jsp page

    Now write any data other than 1 to the InputLogic.jsp to see the working of the notEqual logic tag

    The evaluated here displays the output.jsp as

    read more “Logic Equal Tag (...)”