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 |
name | The variable to be matched is the JSP bean specified by this attribute, if |
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 |
scope | The bean scope within which to search for the bean named by the |
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 |
name | The variable to be matched is the JSP bean specified by this attribute, if |
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 |
scope | The bean scope within which to search for the bean named by the |
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..
Example code
Creating an Action Class
Develop a simple action class LogicAction.java.
|
Creating Form Bean
Our form bean class contains only one property text. Here is the code of FormBean (Logic
Form
.java)
|
Defining form Bean in struts-config.xml file
Add the following entry in the struts-config.xml file for defining the form bean
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> TagsEnter text:The <logic:match>tag works if the enteredtext contains "amit"The <logic:notMatch>tag always evaluate theentered 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...The text entered is:
|
Add the following line in the index.jsp to call the form.
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
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
The
0 comments:
Post a Comment