Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Struts快速学习指南15(内部培训教材)-大部分素材来自于《Programming Jakarta Struts》一书

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

1.1.1           form标签

Strutsform标签是最重要的标签之一,他包装了HTML的标准form标签,提供了将HTML formActionForm 连接起来的功能。

HTML form中的每一个域对应ActionForm的一个属性,当提交HTML from后,Struts根据匹配关系,将HTML from域的值赋给ActionForm的同名属性。下表列举了form标签的属性,并且针对每一个属性加以详细说明:

Struts form标签属性列表

Name

Description

action

form提交的目标地址,action用来选择一个Struts Action对提交后的客户请求进行处理。通过和action的path属性进行匹配来选择Struts Action

如果在web.xml中设置的servlet映射是扩展名映射,则可以用以下方式进行Action匹配(扩展名可以不作为匹配内容)

<html:form action="login.do" focus="accessNumber">

上面的语句表示form提交后,交给path属性值为loginAction进行处理

如果在web.xml中设置的servlet映射是路径映射,则action的值必须完全匹配Struts Actionpath属性值,例如:

<html:form action="login" focus="accessNumber">

enctype

提交form使用的编码方式

focus

页面初始化时光标定位的输入控件名

method

提交请求的HTTP方式(‘POST’ or ‘GET’)

name

对应的ActionForm的名字 ,如果不指定,则使用Struts Action在配置文件中name属性所指定的ActionForm

onreset

form重置时执行的Javascript

onsubmit

form提交时执行的javascript

scope

form对应的ActionForm的有效区域,可以为request session

style

CSS样式表The CSS styles to be applied to this HTML element.

styleClass

CSS样式类别

styleId

HTML元素的ID

target

form提交的目标frame

type

form对应的ActionForm的类名

 

1.2  Struts Logic标签

Struts Logic标签库中包含的标签列表

Tag name

Description

empty

如果标签parameterpropertie属性所指定的变量值为null或空字符串,则处理标签包含的内容

equal

如果标签parameterpropertie属性所指定的变量的值等于标签value属性所指定的值,则处理标签所包含的内容,如:

<logic:equal value="modify" property="action"  name="projectForm">

    <bean:message key="project.project_modify"/>

</logic:equal>

上面的示例表示,如果projectFormaction属性等于modify,则处理<bean:message key="project.project_modify"/>语句。

forward

Forward control to the page specified by the ActionForward entry.

greaterEqual

Evaluate the nested body content of this tag if the requested variable is greater than or equal to the specified value.

greaterThan

Evaluate the nested body content of this tag if the requested variable is greater than the specified value.

iterate

Repeat the nested body content of this tag over a specified collection.

lessEqual

Evaluate the nested body content of this tag if the requested variable is less than or equal to the specified value.

lessThan

Evaluate the nested body content of this tag if the requested variable is less than the specified value.

match

Evaluate the nested body content of this tag if the specified value is an appropriate substring of the requested variable.

messagesNotPresent

Generate the nested body content of this tag if the specified message is not present in this request.

messagesPresent

Generate the nested body content of this tag if the specified message is present in this request.

notEmpty

Evaluate the nested body content of this tag if the requested variable is neither null nor an empty string.

notEqual

Evaluate the nested body content of this tag if the requested variable is not equal to the specified value.

notMatch

Evaluate the nested body content of this tag if the specified value is not an appropriate substring of the requested variable.

notPresent

Generate the nested body content of this tag if the specified value is not present in this request.

present

Generate the nested body content of this tag if the specified value is present in this request.

redirect

Render an HTTP redirect.

 

执行比较功能的标签通用属性表

Name

Description

name

The name of a bean to use to compare against the value attribute. If the property attribute is used, the value is compared against the property of the bean, instead of the bean itself.

parameter

The name of a request parameter to compare the value attribute against.

property

The variable to be compared is the property (of the bean specified by the name attribute) specified by this attribute. The property reference can be simple, nested, and/or indexed.

scope

The scope within which to search for the bean named by the name attribute. All scopes will be searched if not specified.

value

The constant value to which the variable, specified by another attribute(s) of this tag, will be compared.

 

示例:

To check whether a particular request parameter is present, you can use the Logic present tag:

<logic:present parameter="id">

  <!-- Print out the request parameter id value -->

</logic:present>

To check whether a collection is empty before iterating over it, you can use the notEmpty tag:

<logic:notEmpty name="userSummary" property="addresses">

  <!-- Iterate and print out the user's addresses -->

</logic:notEmpty>

Finally, here's how to compare a number value against a property within an ActionForm:

<logic:lessThan property="age" value="21"> 

  <!-- Display a message about the user's age -->

</logic:lessThan>

 




相关文章

相关软件