struts1.x标签

Struts1.x标签

html 标签,用来生成html代码。

<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html lang="true">

  <head>   

    <title>useBean.jsp</title>

  </head> 

  <body>

  <center>    

    <html:form action="useBean.do" method="post">

    <html:hidden property="action" value="add"/>

    账号:<html:text property="person.account"></html:text><br/>

    姓名:<html:password property="person.name"></html:password><br/>

    <html:submit value="提交"></html:submit>

    <html:reset value="重置"></html:reset>

    </html:form>

  </center>   

  </body>

</html:html>

与表单相关的标签:

其中的property属性对应html中的name属性。

Struts1.x中的html标签

一般html

<html:form>

<form>

<html:text>

<input type=text>

<html:password>

<input type=password>

<html:hidden>

<input type=hidden>

<html:submit>

<input type=submit>

<html:reset>

<input type=reset>

<html:file>

<input type=file>

<html:mutibox>

<html:checkbox>

<input type=checkbox>

<html:radio>

<input type=radio>

<html:select>

<select>

<html:option>

<option>

<html:textarea>

<textarea>

<html:image>

<input type=image>

其中,<html:multibox><html:checkbox>都显示为多选框,区别是<html:multibox>初始化时可以同时选定多个值,<html:checkbox>初始化时只能选定一个。不同的输入框对应不同的属性类型,例如文件域会对应FormFile类型。

除了与表单相关的标签,还有<html:errors><html:messages>用于显示资源国际化信息的标签等。

bean标签:用于操作POJOCookieHeaderStruts对象等。

<bean:write>能输出requestSessionapplicationpage中能够访问到的变量。与EL不同是变量不存在或访问不到时,会抛出异常。

<%@ page language="java" pageEncoding="UTF-8"%>

<%@ page import="com.hym.struts.vo.Person" %>

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

<%

    Person person = new Person() ;

    person.setAccount(123456) ;

    person.setName("hym") ; 

    request.setAttribute("person",person) ;

%>

<bean:write name="person" /><br/>

账号:<bean:write name="person" property="account"/><br/>

姓名:<bean:write name="person" property="name"/><br/>

 

<bean:cookie><bean:parameter><bean:header>用于获取cookieparameter(地址栏)header中的对象。这几个标签不能输出,只能将获取的对象保存包另一个变量中,供其它标签使用,或者用<bean:write>输出:

<%@ page language="java" pageEncoding="UTF-8"%>

<%@ page import="com.hym.struts.vo.Person" %>

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

<%

    Person person = new Person() ;

    person.setAccount(123456) ;

    person.setName("hym") ; 

    request.setAttribute("person",person) ;

%>

<bean:write name="person" /><br/>

账号:<bean:write name="person" property="account"/><br/>

姓名:<bean:write name="person" property="name"/><br/>

 

<bean:parameter id="action" name="action"/>

action<bean:write name="action"/><br/>

<bean:header id="host" name="host"/>

host<bean:write name="host"/> <br/>

<bean:cookie id="sessionid" name="JSESSIONID"/>

sessionid<bean:write name="sessionid" property="value"/><br/>

<bean:message>显示资源国际化信息,可带参数,如:<bean:message key=tag.info arg0=hello arg1=hym>

<bean:page>检索JSP隐式对象。

<bean:resource>可以获取本Web程序的资源,name为资源的路径。

<bean:resource id="web_info" name="/WEB-INF/web.xml"/>

web_info:<bean:write name="web_info"/>

<bean:struts>获取struts配置。

<bean:include>将一个外部文件包含进来。

<bean:size>获取集合对象的长度。

 

logic标签:

由于bean标签经常抛出异常,因此logic常与bean配合使用。

<logic:present><logic:notPresent>:判断对象是否存在。指定Cookie属性时判断Cookie,指定header属性的判断header,指定parameter时判断parameter

<logic:present cookie="JSESSIONID">

<bean:cookie id="sessionid" name="JSESSIONID"/>

sessionid<bean:write name="sessionid" property="value"/><br/>

</logic:present>

<logic:notPresent cookie="JSESSIONID">

    Cookie"JSESSIONID"不存在。<br/>

</logic:notPresent>

   <logic:empty><logic:notEmpty>判断集合是否为空,<logic:equal><logic:notEqual>判断指定对象是否相等。判断cookie值是否等于指定值:

<logic:equal value="4DBD037FD4E6DFA0BA40BD99CC41823D" cookie="JSESSIONID">

cookie值相等。

</logic:equal>

<logic:greaterEqual><logic:greaterThan>等功能类似。

2010-08-10  21:37:06

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值