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 |
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 |
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 |
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 |
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 |
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 |
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..
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" %> <%@ taglib uri="/tags/struts-bean" prefix="bean" %> Using <logic> TagsEnter 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...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 a text string to the InputLogic.jsp page lets you to see the working of the present Logic tag
It displays the following out.jsp page
0 comments:
Post a Comment