struts2的常用标签

    技术2024-07-21  74

    <s:url action="helloworld_add" namespace="/test"><s:param name="psersonid" value="23"/></s:url>生成类似如下路径:/struts/test/helloworld_add.action?personid=23

     

    当标签的属性值作为字符串类型处理时,%符号的用途是计算OGNL表达式的值。  <s:set name="myurl" value="http://www.sina.com"/>   <s:url value="#myurl"/><br>   <s:url value="%{#myurl}"/>输出结果: #myurl            http://www.sina.com

    %{}就是明确告诉程序这就是ognl表达式

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

     

     

    ****表单标签_checkboxxlist复选框如果集合为list <s:checkboxlist name="list" list="{"java","net","ror","php"}"  value="{"java","net"}"/>

     

    运行后的代码:

    <input type="checkbox" name="list" value="java" id="list-1" checked="checked"/><label for="list-1" class="checkboxLabel">java</label><input type="checkbox" name="list" value="c++" id="list-2"/><label for="list-2" class="checkboxLabel">c++</label><input type="checkbox" name="list" value=".net" id="list-3" checked="checked"/><label for="list-3" class="checkboxLabel">.net</label><input type="checkbox" name="list" value="opengl" id="list-4"/><label for="list-4" class="checkboxLabel">opengl</label><input type="hidden" id="__multiselect_list" name="__multiselect_list" value="" /> 

     

    如果集合为map

    <s:checkboxlist name="map" list="#{1:'java',2:'c++',3:'.net',4:'opengl'}" listKey="key" listValue="value" value="{1,2,3}"/>       <input type="checkbox" name="map" value="1" id="map-1" checked="checked"/><label for="map-1" class="checkboxLabel">java</label><input type="checkbox" name="map" value="2" id="map-2" checked="checked"/><label for="map-2" class="checkboxLabel">c++</label><input type="checkbox" name="map" value="3" id="map-3" checked="checked"/><label for="map-3" class="checkboxLabel">.net</label><input type="checkbox" name="map" value="4" id="map-4"/><label for="map-4" class="checkboxLabel">opengl</label><input type="hidden" id="__multiselect_map" name="__multiselect_map" value="" /> 

     

     

    里面有很多不需要的标签 为了去掉这些struts自动生成乱七八糟的标签 需要

     <!-- 默认的视图主题    <constant name="struts.ui.theme" value="simple" />设计这样。。就ok了

     

     

     

    表单标签radio单选框该标签的使用和checkboxlist复选框相同如果该集合里存放的是javabean(psersonid和name为person的属性)<s:radio name="beans" list="#request.persons" listKey="psersonid" listValue="name"/>

     

     

     

     

     

     

     

    最新回复(0)