struts标签

1、优点:

  1. 便于维护
  2. 界面清晰
  3. 便于重用

2、常用的struts taglib

   1、<bean:write>:输出处理
   2、<logic:empty><logic:notEmpty>:数据判断
   3、<logic:present><logic:notPresent>
   4、<logic:iterator>:循环

logic标签相当于if语句的判断,for循环
html标签不建议使用,封装了表单,耦合性太强,国际化和异常处理时会用到

不使用struts1的原因:侵入性强

3、搭建struts标签的环境:和国际化资源文件关联MessageResources.properties

1、在struts-config.xml中配置
国际化资源文件的基名MessageResources 放在src下

<message-resources parameter="MessageResources" />

2、在src下导入MessageResources.properties文件

4、使用:

1、在jsp页面中导入taglib指令标签

<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%> 
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic"%> 
<bean:write name="hello"/>

name属性的含义:到scope属性里找变量hello的值

1、

bj(default):<bean:write name="bj"/><br>
bj(filter="true"):<bean:write name="bj" filter="true"/><br>
bj(filter="false"):<bean:write name="bj" filter="false"/><br>

显示结果:
bj(default):北京欢迎您
bj(filter=”true”):北京欢迎您
bj(filter=”false”):北京欢迎您
filter=”true”含义为:不对输出的html文本进行解释,原样向客户端输出
filter=”false” 含义为:对输出的html文本解释后,向客户端输出
默认为不解释

2、

today(default):<bean:write name="today"/><br>
today(format="yyyy-MM-dd HH:mm:ss"):<bean:write name="today" format="yyyy-MM-dd HH:mm:ss"/>

显示结果:
today(default):Mon Aug 20 23:48:50 CST 2018
today(format=”yyyy-MM-dd HH:mm:ss”):2018-08-20 23:48:50

3、

扫描二维码关注公众号,回复: 2896969 查看本文章
<input type="text" value="<bean:write name="user" property="username"/>"><br>

name属性的含义:到scope中找相应变量的值(如变量user 、对象),并调用getUsername取出username的值,并在浏览器中在text文本框中输出

4、

<input type="text" value="<bean:write name="user" property="group.name"/>"><br>

name属性的含义:到scope中找相应变量的值(如变量user 、对象),并调用getGroup()取出ground的值,通过get方法导航到group取得所指对象的name值并在浏览器中在text文本框中输出

5、

<logic:empty name="attr1">
         attr1为空<br>
</logic:empty>
<logic:notEmpty name="attr1">
         attr1不为空<br>
</logic:notEmpty>

若scope中变量的值设为null或attr1的值没有被设定(空串),则执行标签体内的语句

6、

<logic:present name="attr1">
         attr1存在<br>
</logic:present>
<logic:notPresent name="attr1">
        attr1不存在<br>
</logic:notPresent>

若scope中的变量存在(值被设定,不为null),则执行标签体内的语句

7、

<logic:notEmpty name="userlist">
              <logic:iterate id="u" name="userlist">
                  <tr>
                       <td>
                            <bean:write name="u" property="username"/>
                       </td>
                       <td>
                            <bean:write name="u" property="age"/>
                       </td>
                       <td>
                            <bean:write name="u" property="group.name"/>
                       </td>
                  </tr>
              </logic:iterate>
</logic:notEmpty>

从scope中取出变量userlist的值(集合)的各个元素(user对象)放入scope(scope=page),其变量为u
从scope中取出变量u的值(user对象),取得该对象的各个属性值并显示

5、myEclipse下的目录

src:WEB-INF/classes
WebRoot:项目名

6、空集合、空串、null都叫为空

猜你喜欢

转载自blog.csdn.net/Pluto__lxh/article/details/82107283