Struts提供了五个标签库,即:HTML、Bean、Logic、Template和Nested。

HTML标签 : 用来创建能够和Struts 框架和其他相应的HTML 标签交互的HTML 输入表单

Bean标签:  在访问JavaBeans 及其属性,以及定义一个新的bean 时使用

Logic标签: 管理条件产生的输出和对象集产生的循环

Template标签:随着Tiles框架包的出现,此标记已开始减少使用

Nested标签:  增强对其他的Struts 标签的嵌套使用的能力

<%@ taglib  uri="/WEB-INF/struts-html.tld" prefix="html" %>来导入相应的配置文件,使用别名prefix即可调用标签库设定的标记
Html struts-html.tld
Bean struts-bean.tld
Logic struts-logic.tld
Tiles struts-tiles.tld
Nested struts-nested.tld

一:HTML标签

<%@ taglib  uri="/WEB-INF/struts-html.tld" prefix="html" %>

Property属性值的名字,相当于input里面的name属性

form表单  <html:form action="reg.do" method="post">
文本框 <html:text property="username" value="test"/>
密码框 <html:password property="userpass"/>
单选
<html:radio property="gender" value=""/>男
<html:radio property="gender" value=""/>女
复选
<html:multibox property="hobby" value="看书"/>看书
<html:multibox property="hobby" value="睡觉"/>睡觉
<html:multibox property="hobby" value="编程"/>编程

文本区 <html:textarea property="memo" rows="5" cols="60"/>

<html:hidden property="id" value="12"/>
  <html:submit>提交</html:submit> or <html:submit value=”提交”/>
  <html:reset>清除</html:reset>
  <html:cancel>取消</html:cancel>

下拉
LabelValueBean lvbean=new LabelValueBean();
lvbean.setLabel(""+i);
lvbean.setValue(""+i);
list.add(lvbean);
年龄 (它比较特殊,必须用到集合对象才可以往标签里添加下拉数据,它是以LABLE与 VALUE存取)在ActionForm里获取的也是它设置的VALUE值。
<html:select property="age">
<html:options collection="list" labelProperty="label" property="value"/>
</html:select> optionsCollection:
<html:select property="username">
   <html:optionsCollection name="userList" label="username" value="userID"/>
</html:select> options:
<html:select property="username">
   <html:options collection="userList" property="userID" labelProperty="username"/>
</html:select>

二:logic标签

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<logic:empty name="grade" scope="request">
<span>不存在</span>
</logic:empty><logic:notEmpty name="grade" scope="session">
<span>存在</span>
</logic:notEmpty>
logic:equals标签:
<c:forEach items="${requestScope.userList}" var="usr"><logic:equal name="usr" property="userID" value="${sessionScope.currUser.userID}">
<a href="#">编辑个人信息</a>
</logic:equal>
</c:forEach>
<logic:notEqual>
  <span>不存在</span>
</logic:notEqual>
logic:iterate标签
<logic:iterate id="usr" name="userList">
${usr.username}
</logic:iterate>

三:bean标签

<bean:write name="person"property="name"/>
<bean:message  key="greeting" arg1="good morning" arg2="goodevening"/>在资源文件中greeting的配置举例如下:greeting = hello, {0}, {1}.
<bean:parameter id="ok" name="orgId"/>
<bean:write name="ok"/>
<bean:sizeid="size" name="userList"/>
<bean:write name="size"/>

四:nested标签

nested中的一半标签和html中的标签用法作用完全相同

<nested:text property="lastName"/>
<nested:password property="lastName"/>
<nested:checkbox property="lastName"/>
<nested:radio property="lastName"/>
<nested:nest property="user">标签,将按照层次编码
   <nested:nest property="user">
帐号:<nested:write property="account"/>
</nested:nest>
<nested:nest property="userInfo">
姓名:<nested:write property="name"/>
性别:<nested:write property="sex"/>
</nested:nest>
由于user和userInfo本身就是嵌套的,所以第二种方式就在actionForm中使用一个User user属性即可:
<nested:nest property="user">
帐号:<nested:write property="account"/>
<nested:nest property="userInfo">
姓名:<nested:write property="name"/>
性别:<nested:write property="sex"/>
</nested:nest>
</nested:nest>

struts1标签库的更多相关文章

  1. Struts1 标签库 说明

    Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML标签 : 用来创建能够和Struts 框架和其他相应的HTML 标签交互的HTML 输入表单 ...

  2. Struts1标签

    Struts1 标签库  说明 Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML 标签 : 用来创建能够和Struts 框架和其他相应的HT ...

  3. 【转】Struts1.x系列教程(4):标签库概述与安装

    转载地址:http://www.blogjava.net/nokiaguy/archive/2009/01/archive/2009/01/archive/2009/01/archive/2009/0 ...

  4. 【转】Struts1.x系列教程(7):Logic标签库

    转载地址:http://www.blogjava.net/nokiaguy/archive/2009/01/archive/2009/01/archive/2009/01/archive/2009/0 ...

  5. 【转】Struts1.x系列教程(6):Bean标签库

    转载地址:http://www.blogjava.net/nokiaguy/archive/2009/01/archive/2009/01/archive/2009/01/archive/2009/0 ...

  6. 【转】Struts1.x系列教程(5):HTML标签库

    转载地址:http://www.blogjava.net/nokiaguy/archive/2009/01/archive/2009/01/archive/2009/01/archive/2009/0 ...

  7. java开发--struts2 标签库使用

    在工程中使用struts2标签 一.struts2标签定义文件在struts2-core-2.0.11.1\META-INF 下面,文件名为struts-tags.tld 二.如果工程使用了servl ...

  8. struts2 标签库 介绍

    struts2.0里的标签没有分类,只用在jsp头文件加上<%@ taglib prefix="s" uri="/struts-tags" %>就能 ...

  9. Struts2之Struts2的标签库

    前言: Struts2提供了大量的标签 ,用来帮助开发表现层页面,这些表现一方面解决了美观性的需求,因为它们具有html标签一样的外观,另一方面它们解决了功能性的需求, 因为它们具有jsp脚本一样的逻 ...

随机推荐

  1. VR头盔产品镜片评测

    2015-07-21 16:59 原创 Randy Orton http://www.leiphone.com/news/201507/7j46BjWsSitKML13.html 虚拟现实设备自从去年 ...

  2. python3 requests模块 基本操作

    import requests import json # 1.HTTP方法 requests.get('https://github.com/timeline.json') #GET请求 reque ...

  3. struts2学习笔记 day02 获取参数 访问ServletAPI 结果类型

  4. 51Nod 1099 任务执行顺序 (贪心)

    #include <iostream> #include <algorithm> using namespace std; +; struct node{ int r, q; ...

  5. UVA10305:Ordering Tasks(拓扑排序)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  6. linux下输出json字符串,用python格式化

    echo '{"name":"chen","age":"11"}' |python -m json.tool 如果是文件 ...

  7. 类加载机制 + Classloader.loadClass(String name)和Class.forName(String name)

    Classloader.loadClass(String name)和Class.forName(String name)的区别 Java的类在jvm中的加载大致分为加载,链接或者叫link(里面包含 ...

  8. 一些API

    /** * Goto the specified frame index, and pause at this index. * @param startIndex The animation wil ...

  9. httpd.exe占用100%CPU

    客户VPShttpd.exe进程占用100%CPU百度搜了下,很多文章: 在网上也没有能够直接找到比较好的解决方法,后来在一个帖子上看到说,有可能是apache与其他的软件冲突了(参考http://t ...

  10. [android][windows][使用HAXM加速模拟器][不使用SDK manager]

    网上找到了来使用HAXM,可惜我在sdk manager上下载不了,也使用过勾上[fetching...]那个选项,依然无效. 所以自己手动下载来安装和使用. 具体的教程可以参考http://blog ...