创建 JSP 页面 IfControlTag.jsp
Set a property 'technologyName' with a value 'Java' as
<s:set name="technologyName" value="%{'Java'}"/>
IfControlTag.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Struts 2 Control Tag Example</title>
</head>
<body>
<s:set name="technologyName" value="%{'Java'}"/>
<s:if test="%{#technologyName=='Java'}">
<div><s:property value="%{#technologyName}" /></div>
</s:if>
<s:elseif test="%{#technologyName=='Jav'}">
<div><s:property value="%{#technologyName}" /></div>
</s:elseif>
<s:else>
<div>Technology Value is not Java</div>
</s:else>
</body>
</html>
struts.xml: Add the following xml snippet in the struts.xml file
<action name="doIf" >
<result>/pages/genericTags/IfControlTag.jsp</result>
</action>
In the IfControlTag.jsp only <s:if> tag evaluates to true
<s:if test="%{#technologyName=='Java'}">
<div><s:property value="%{#technologyName}" /></div>
</s:if>
So we get the output equal to Java

本文介绍了一个使用Struts 2框架中的控制标签(If标签)的示例,展示了如何设置属性并根据该属性显示不同的内容。具体通过设置技术名称为'Java',并使用If标签来判断是否等于'Java'来决定展示的内容。
5636

被折叠的 条评论
为什么被折叠?



