Struts2 Control Tags - If Tag
Struts2 if tag can be used for basic conditional flow. Using OGNL syntax, all types of conditional checks are possible. This tag can be followed with elseif and else blocks. Given below are some examples of if tag usage.
Sample application demonstrating usage of Struts2 if tag
This sample contains a single page with a link. Whenever user clicks on the link, the clicked link name is shown below.
When a link is clicked, its id is copied to the linkid hidden field using JavaScript and IfDemo action is invoked. Struts2 automatically maps this hidden field to linkid field in IfDemo action class. Then it renders the ifdemo.jsp. At this point, class variables in IfDemo action class are automatically available in ifdemo.jsp (since they are pushed to value stack). The if tag in JSP checks for the value of linkid in value stack and prints it out.
Action Class - IfDemo.java
Struts configuration - struts.xml
Sample screen - ifdemo.jsp