Struts2的通用标签

1.数据标签

          <h3>set</h3>
          <!-- 在ognl上下文的根对象中取result的值,付给test1 -->
          <s:set var="test1" value="result"></s:set>
          ${test1 },${requestScope.test1 }
		          
          <h3>property</h3>
          <!-- 默认取栈顶 -->
          <s:property/>,
          <!-- 取栈顶的值 -->
          <s:property value="num1" />,
          <!-- 取根对象指定的属性值 -->
          <s:property value="cal2.num1" />
          <!-- 取非根对象的值 -->
          <s:property value="#request.cal2.num1" />
          
          <h3>push</h3>
          <!-- 把需要获取的值弹到栈顶 -->
          <s:property/>
          <s:push value="result">
          	<s:property/>
          </s:push>
          <s:property/>
          
          <h3>action</h3>
          <!-- 通常来获取后台请求,初始化值 -->
          <s:action name="TagAction" namespace="/sy" var="test2" ></s:action>
          <s:property value="test2" />
          
		          
          <h3>url</h3>
          <!-- 生成地址所用,注意与a标签区分 -->	
          <s:url namespace="/sy" action="TagAction" var="test3" ></s:url>
          <s:property value="#test3" />
          <s:a href='<s:property value="#test3" />'>aaa</s:a>
          <a href="%{#test3}">xxx</a>
			          
          <h3>param</h3>
          <!-- param两种赋值方式,ognl表达式,字符串 -->
          <s:url namespace="/sy" action="TagAction" var="test4" >
          	<s:param name="test5">sad</s:param>
          	<s:param name="test6" value="num1"></s:param>
          </s:url>
		  <s:property value="#test4" />          
          
          <h3>date</h3>
          <!-- 时间格式 -->
          <%
          	request.setAttribute("currentDate", new Date());
          	request.setAttribute("score", new Integer(70));
          	request.setAttribute("names", new String[]{"李四","张三","gay"});
          %>
          <s:date name="#request.currentDate" format="yyyy-mm-dd" />
          
          <h3>debug</h3>
          <!-- 查询值栈的值 -->
          <s:debug/> 
          
          
   	 <h3 style="color: red;">控制标签</h3>
   	 	<h3>iterator/if/elseif/else</h3>
          <s:iterator value="#request.names" var="name" >
          	<li>
          		<s:property value="#name" />
          	</li>
          </s:iterator>
          
          <s:if test="#request.score > 80">
          	A
          </s:if>
          <s:elseif test="#request.score > 60">
          	B
          </s:elseif>
          <s:else>
          	C
          </s:else>

2.表单标签

<h3 style="color: red;">表单标签</h3>
          <h3>form</h3>
          <h3>textfield</h3>
          <h3>radio</h3>
          <h3>select</h3>
          <h3>textarea</h3>
          <h3>hidden</h3>
          <h3>submit</h3>
          <s:form action="" namespace="">
          	
          	<s:textfield label="姓名" name="uname"></s:textfield>
          	<%-- <s:radio list="{'男','女'}" name="sex" label="性别" value="男" ></s:radio> --%>
          	<s:radio list="#{1:'男',2:'女'}" name="sex" label="性别" value="2" ></s:radio>
          	<s:select list="#{1:'吃饭',2:'睡觉' }" name="select" ></s:select>
				          	
          </s:form>

猜你喜欢

转载自blog.csdn.net/qq_43162661/article/details/83050871