struts1标签库

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="0"/><html:radio property="gender" value="1"/>女 
 复选    
<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>   
原文地址:https://www.cnblogs.com/estellez/p/3958389.html