stucts1 介绍(英文翻译)

 

Welcome to Struts 1
Struts is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Commons packages, like BeanUtils and Chain of Responsibility. The framework helps you create an extensible development environment for your application, based on published standards and proven design patterns.
Struts是一个灵活的控制层,基于标准的技术,例如java Servlets, JavaBeans, ResourceBundles,XML,以及各种Jakarta的通用包,如BeanUtils 和 责任链。这个框架帮助你为你的应用程序创建一个可扩展的开发环境,基于公开的标准和经过证实的设计模式。
Struts in a Nutshell
The framework provides its own web Controller component and integrates with other technologies to provide the Model and the View. For the Model, the framework can interact with standard data access technologies, like JDBC and EJB, as well as most any third-party packages, like Hibernate, iBATIS, or Object Relational Bridge. For the View, the framework works well with JavaServer Pages, including JSTL and JSF, as well as Velocity Templates, XSLT, and other presentation systems.
这个框架提供他自己的web控制器组件,和其他技术集成来提供模型 和 视图,对于模型,这个框架可以和标准的数据访问技术,如JDBC和EJB交互,也包括大多数第三方的包,如Hibernate , iBATIS , 和 Object Relational Bridge。对于视图,这个框架和JSP工作的很好,包括JSTL和JSF,以及Velocity 模板,XSLT 和其他表现系统。
The framework's Controller acts as a bridge between the application's Model and the web View. When a request is received, the Controller invokes an Action class. The Action class consults with the Model (or, preferably, a Facade representing your Model) to examine or update the application's state. The framework provides an ActionForm class to help transfer data between Model and View.
这个框架的控制器作用就像桥一样,介于应用的模型和web视图之间。当收到一个请求以后,控制器触发一个Action类。这个Action类咨询模型(或者,更准确的说,一个表示你的模型的Façade 外观),来检查或者更新应用的状态。框架提供一个ActionForm类来帮助在模型和视图之间传递数据。
Most often, the Model is represented as a set of JavaBeans. Typically, developers will use the Commons BeanUtils to transfer data between ActionForms and the Model objects (or a Facade). Preferably, the Model will do the "heavy lifting", and the Action will act as a "traffic cop" or adapter.
更常见的情况,模型表现为一系列的JavaBeans。典型情况下,开发者将使用通用的BeanUtils 来在ActionForms和模型对象(或者一个外观)之间来传送数据。作为优选方案,模型将作为“起重机”,Action将类似一个“交通警察”或者适配器。
Struts Config in a Nutshell
A web application uses a deployment descriptor to initialize resources like servlets and taglibs. The deployment descriptor is formatted as a XML document and named "web.xml". Likewise, the framework uses a configuration file to initialize its own resources. These resources include ActionForms to collect input from users, ActionMappings to direct input to server-side Actions, and ActionForwards to select output pages.
Web应用使用发布描述者来初始化所需资源,如servlets和taglibs。这个发布描述者格式化为一个XML文档,命名为web.xml。类似的,框架使用一个配置文件来初始化他自己的资源。这些资源包括ActionForms ,用来从用户收集输入,ActionMappings来引导输入到服务器端的Actions, ActionForwards用来选择输出页面。
Here's a simple configuration (struts-config.xml) for a login workflow:
这里是一个简单的配置文件,用于登陆的工作流定义。
                   
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://struts.apache.org/dtds/struts-config_1_3.dtd">
    <struts-config>
        <form-beans>
            <form-bean
                name="logonForm"
                type="app.LogonForm"/>
        </form-beans>
        <action-mappings>
            <action
                path="/Welcome"
                forward="/pages/Welcome.jsp"/>
            <action
                path="/Logon"
                forward="/pages/Logon.jsp"/>
            <action
                path="/LogonSubmit"
                type="app.LogonAction"
                name="logonForm"
                scope="request"
                validate="true"
                input="/pages/Logon.jsp">
                <forward
                    name="success"
                    path="/pages/Welcome.jsp"/>
                <forward
                    name="failure"
                    path="/pages/Logon.jsp"/>
            </action>
            <action
                path="/Logoff"
                type="app.LogoffAction">
                <forward
                    name="success"
                    path="/pages/Logoff.jsp"/>
            </action>
        </action-mappings>
        <message-resources parameter="resources.application"/>
    </struts-config>
   
               
There are several other resources you can specify in the framework's configuration file. You can specify validations for the ActionForms in an XML descriptor, using the Struts Validator. A standard extension, Tiles, helps you build pages from smaller fragments.
在这个框架的配置文件里,你可以指定一些其他的资源。你可以在一个XML描述文件里面为ActionForm指定验证,使用Struts Validator。一个标准的扩展,Tiles,帮助你从小的碎片构建页面。
Struts is extensible. Every class deployed by the framework can be replaced by your own default class. The properties of your default class can be set using the Digester's set-property feature. This is one reason why there are so many contributor extensions. We provide the base framework, but you can still write your application your way.
Struts是可扩展的。框架发布的每个类都可以替换成你自己的缺省的类。你自己缺省类的属性可以使用Digester的set-property特征来进行设置。这就是为什么框架里面有这么多contributor extension的原因之一。我们提供基本框架,同时你仍然可以按照你的方式来编写你的应用程序。
For more about the framework and its underlying technologies, see the User Guide.
要更多的了解框架和他底层技术,参见User Guide。
Is Struts the best choice for every project?
No. If you need to write a very simple application, with a handful of pages, then you might consider a "Model 1" solution that uses only server pages.
不是。如果你需要写一个非常简单的应用,有限的几个页面,那么你可以考虑一个Model 1方式的解决方案,仅使用服务端页面。
But, if you are writing a more complicated application, with dozens of pages, that need to be maintained over time, then Struts can help. For more about whether Model 1 or MVC/Model 2 is right for you, see Understanding JavaServer Pages Model 2 architecture.
但是,如果你在写一个更加复杂的应用,有成打的页面,需要不时进行维护,那么Struts能够帮你。要更多了解 Model 1 还是 MVC/Model 2 适合于你,参见
Understanding JavaServer Pages Model 2 architecture.


Table of Contents
• 1. Introduction
o 1.1 Forward into the Past!
o
 1.2.1 The Model: System State and Business Logic JavaBeans
 1.2.2 The View: JSP Pages and Presentation Components
 1.2.3 The Controller: ActionServlet and ActionMapping
o 1.3 Control Flow
• 2. Building Model Components
o 2.1 Overview
o 2.2 JavaBeans and Scope
o 2.3 ActionForm Beans
o 2.4 System State Beans
o 2.5 Business Logic Beans
• 3. Building View Components
o 3.1 Overview
o 3.2 Internationalization
o 3.3 Forms and FormBean Interactions
 3.3.1 Automatic Form Population
 3.3.2 Automatic Form Validation
 3.3.3 The Struts Validator
 3.3.4 Page Composition With Tiles
o 3.4 Presentation Frameworks
o 3.4 Direct Presentation Techniques
 3.4.1 Image Rendering Components
 3.4.2 Rendering Text
• 4. Building Controller Components
o 4.1 Overview
o 4.2 The ActionServlet
 4.2.1 Request Processor
o 4.3 ActionForm Classes
 4.3.1 DynaActionForm Classes
 4.3.2 LazyActionForm Classes
 4.3.3 Map-backed ActionForm Classes
o 4.4 Action Classes
 4.4.1 Action Class Design Guidelines
o 4.5 Exception Handler
o 4.6 Plugin Classes
o 4.7 The ActionMapping Implementation
o 4.8 Writing ActionMappings
 4.8.1 ActionMapping Example
o 4.9 Using ActionMappings for Pages
o 4.10 Using Wildcards in ActionMappings
o 4.11 Using The Commons Logging Interface
• 5. Configuring Applications
o 5.1 Overview
o 5.2 The Configuration File
 5.2.1 Controller Configuration
 5.2.2 Message Resources Configuration
 5.2.3 PlugIn Configuration
o 5.3 Configuring your application for modules
 5.3.1 Module Configuration Files
 5.3.2 Informing the Controller
 5.3.3 Switching Modules
o 5.4 The Web Application Deployment Descriptor
 5.4.1 Configure the Action Servlet Instance
 5.4.2 Configure the Action Servlet Mapping
 5.4.3 Configure Struts Taglib"
o 5.5 Add Framework Components To Your Application
o 5.6 Logging
• 6. Getting Started
o 6.1 Release Notes
 Release Notes 1.3.7 (Beta)
 Release Notes 1.3.6 (Test Build)
 Release Notes 1.3.5
 Release Notes 1.3.3 (Test Build)
 Release Notes 1.3.2
 Release Notes 1.3.1 (Test Build)
 Release Notes 1.2.9
 Release Notes 1.2.8
 Release Notes 1.2.7
 Release Notes 1.2.4
 Release Notes 1.1
 Release Notes 1.1-rc2
 Release Notes 1.1-rc1
 Release Notes 1.1-b3
 Release Notes 1.1-b2
 Release Notes 1.1-b1
o 6.2 Installation
 iPlanet
 Portal Application Server
 Jetty
 JRun 3.0
 Orion Application Server
 SilverStream Application Server 3.7.1 and later
 Tomcat with Apache
 Bluestone Universal Business Server 7.2
 WebSphere Application Server 3.5 FixPack 2
 WAS with the Example Applcation
 Weblogic 5.1 sp8

1. Introduction
"Read the directions and directly you will be directed in the right direction."
看看指示牌,你将直接被指到正确的方向。
The framework documentation is written for active web developers and assumes a working knowledge about how Java web applications are built. For more about the underlying nuts and bolts, see the Key Technologies Primer.
框架的文档是为实际的web开发人员编写的,假定对于Java web应用如何构建有实际工作经验。对于更多的底层的螺丝和螺栓,参见 Key Technologies Primer.
1.1 Forward into the Past! (or a brief history of Struts)
When Java servlets were first invented, many programmers quickly realized that they were a Good Thing. They were faster and more powerful that standard CGI, portable, and infinitely extensible.
当Java servlet第一次发明出来时,许多程序员很快认识到他是一个好东西。他比标准的CGI更快,更强大,可移植,具有无限的扩展性。
But writing HTML to send to the browser in endless println() statements was tiresome and problematic. The answer to that was JavaServer Pages, which turned Servlet writing inside-out. Now developers could easily mix HTML with Java code, and have all the advantages of servlets. The sky was the limit!
但是编写HTML,发送给浏览器无止境的println()语句是令人厌倦的和错误百出的。对这一切的回答是 JavaServer Page,它使得Servlet编写转变为内部对象-out。现在开发人员可以轻松的混合HTML和Java代码,同时拥有servlet的所有优点。只有天空才成为极限!
Java web applications quickly became "JSP-centric". This in-and-of itself was not a Bad Thing, but it did little to resolve flow control issues and other problems endemic to web applications.
Java web应用程序很快变成了“以JSP为中心”。这种输入-并且-自我处理 并不是一件坏事,但他没有解决流程控制和其他对于web应用来说特定的问题。
Clearly, another paradigm was needed ...
很清楚,需要另外一个模型图。。。
Many clever developers realized that JavaServer Pages AND servlets could be used together to deploy web applications. The servlets could help with the control-flow, and the JSPs could focus on the nasty business of writing HTML. In due course, using JSPs and servlets together became known as Model 2 (meaning, presumably, that using JSPs alone was Model 1).
一些聪明的开发人员认识到JavaServer Page和 servlet可以联合起来构建web 应用。Servlet可以帮助处理控制流,JSP可以集中在编写HTML的下等生意上。在适当教训后,联合使用JSP和servlet变成了Model 2(意思是,可以推断出,单独使用JSP称为Model 1)
Of course, there is nothing new under the Sun ... and many have been quick to point out that JSP's Model 2 follows the classic Model-View-Controller design pattern abstracted from the venerable Smalltalk MVC framework. Java Web developers now tend to use the terms Model 2 and MVC interchangeably. In this guide, we use the MVC paradigm to describe the framework architecture, which might be best termed a Model 2/MVC design.
当然,太阳底下无新事。。。许多人很快指出JSP的Model2 遵循经典的MVC设计模式,从可敬的Smalltalk MVC框架中抽象得到。Java web开发人员现在倾向于互换使用Model 2 和 MVC这两个名词。在这个向导中,我们使用MVC 来描述框架的架构,可以更高的被称为一个Model2 / MVC 设计。
The Apache Struts Project was launched in May 2000 by Craig R. McClanahan to provide a standard MVC framework to the Java community. In July 2001, version 1.0 was released, and IOHO, Java Model 2 development has never been quite the same.
Apache Struts项目开始于2000年5月,由Craig R McClanahan发布,为Java 社区提供一个标准的MVC框架。在2001年4月,发布版本1.0,看来,Java Model2 的开发也不是与众不同。
1.2 The Model-View-Controller ('MVC') Design Pattern
The term "MVC" originated with the SmallTalk Model-View-Controller framework. Under MVC, an application is seen as having three distinct parts. The problem domain is represented by the Model. The output to the user is represented by the View. And, the input from the user is represented by Controller.
MVC术语源于SmallTalk Model-View-Controller框架。在MVC模式下,一个应用看成拥有三个独立的部分。问题域使用模型来表示。输出到用户的用视图来表示。用户的输入用控制来表示。
1.2.1 The Model: System State and Business Logic JavaBeans
The Model portion of an MVC-based system can be often be divided into two major subsystems -- the internal state of the system and the actions that can be taken to change that state.
基于MVC的系统中,Model部分经常分为两个主要的子系统――系统的内部状态 和 可以用来改变这些状态的action 行为。
In grammatical terms, we might think about state information as nouns (things) and actions as verbs (changes to the state of those things).
在语法中,我们可以认为状态信息是名词(事情),action是动词(改变这些事情的状态)
Many applications represent the internal state of the system as a set of one or more JavaBeans. The bean properties represent the details of the system' state. Depending on your application's complexity, these beans may be self contained (and know how to persist their own state), or they may be facades that know how to retrieve the system's state from another component. This component may be a database, a search engine, an Entity Enterprise JavaBean, a LDAP server, or something else entirely.
许多应用程序将系统的内部状态表示为一系列的JavaBean 。bean 的属性表示了系统状态的细节。和你的应用复杂度相关,这些Bean可能是自包含的(知道怎样来保存自己的状态),或者他们可以被包装,知道怎样从其他组件来检索系统的状态。这个组建可以使一个数据库,一个搜索引擎,一个实体EJB,一个LDAP服务器,或者其他任何东西。
Large-scale applications will often represent the set of possible business operations as methods that can be called on the bean or beans maintaining the state information. For example, you might have a shopping cart bean, stored in session scope for each current user, with properties that represent the current set of items that the user has decided to purchase. This bean might also have a checkOut() method that authorizes the user's credit card and sends the order to the warehouse to be picked and shipped. Other systems will represent the available operations separately, perhaps as Session Enterprise JavaBeans (Session EJBs).
大规模应用中,一系列可能的业务操作经常表示为可以调用的Bean的方法,或者维持状态的Bean的方法。例如,你可以有一个购物筐bean,每个当前用户存储在session 范围,它的属性表示了当前用户决定购买的一系列条目。这个bean可能有一个checkOut()方法,认证用户的信用卡发送订单到仓库来检出和发货。其他系统将单独表示可用的操作,可能是Session EJB。
In a smaller scale application, on the other hand, the available operations might be embedded within the Action classes that are part of the framework control layer. This can be useful when the logic is very simple or where reuse of the business logic in other environments is not contemplated.
在一个小规模应用中,另一方面,可能的操作可能被集成到Action类中,它是框架控制层的一部分。这个在逻辑非常简单或者在其他情况重用逻辑不被重视时可能是有用的。(语气极不肯定)
The framework architecture is flexible enough to support most any approach to accessing the Model, but we strongly recommend that you separate the business logic ("how it's done") from the role that Action classes play ("what to do"). 'nuff said.
框架结构是足够灵活的,可以支持几乎任何方式来访问模型,但我们强烈建议你将业务逻辑(它是怎么做的)从Action类中分离出来。(该做点啥)
For more about adapting your application's Model to the framework, see the Building Model Components chapter.
关于如果调整你的应用模型来使用框架,参见Building Model Components这一章。
1.2.2 The View: JSP Pages and Presentation Components
The View portion of a Struts-based application is most often constructed using JavaServer Pages (JSP) technology. JSP pages can contain static HTML (or XML) text called "template text", plus the ability to insert dynamic content based on the interpretation (at page request time) of special action tags. The JSP environment includes a set of standard action tags, such as <jsp:useBean> whose purpose is described in the JavaServer Pages Specification. In addition to the built-in actions, there is a standard facility to define your own tags, which are organized into "custom tag libraries."
基于Struts的应用中,视图部分经常使用JSP技术来构建。JSP页面可以包含静态的HTML或XML文本,称为“模板文本”,加上在页面请求时间的解释而插入生成的动态内容,根据特定的action tag。JSP环境包括一系列标准的action tag,例如<jsp:useBean>它的功能在JavaServer Pages 规范中描述。除了内置的action,可以通过标准的过程来定义你自己的tag,组织起来称为“客户标签库”。
The framework includes a set of custom tag libraries that facilitate creating user interfaces that are fully internationalized and interact gracefully with ActionForm beans. ActionForms capture and validate whatever input is required by the application.
框架包含一希勒的客户标签库 ,它简化了创建用户界面的过程,完全是国际化的,可以友好的和ActionForm进行交互。ActionForm捕捉和验证输入是否是应用所需要的。
For more about the Struts taglibs and using presentation pages with the framework, see the Building View Components section. Additional documentation regarding the taglibs is also available in the Taglibs subproject.
更多关于Struts 标签库和使用框架的表现页面,参见Building View Components 章节。关于标签库的额外文档在 Taglibs子项目组也可以得到。
1.2.3 The Controller: ActionServlet and ActionMapping
Struts provides the Controller portion of the application. The Controller is focused on receiving requests from the client (typically a user running a web browser), deciding what business logic function is to be performed, and then delegating responsibility for producing the next phase of the user interface to an appropriate View component. The primary component of the Controller in the framework is a servlet of class ActionServlet. This servlet is configured by defining a set of ActionMappings. An ActionMapping defines a path that is matched against the request URI of the incoming request and usually specifies the fully qualified class name of an Action class. All Actions are subclassed from [org.apache.struts.action.Action]. Actions encapsulate calls to business logic classes, interpret the outcome, and ultimately dispatch control to the appropriate View component to create the response. While the framework dispatches to a View, actually rendering the View is outside its scope.
Struts提供应用的控制器部分。控制器集中在接受用户请求(典型情况下用户使用浏览器),决定哪个业务逻辑功能将被执行,然后将生成用户界面的功能转交给对应的视图部分完成。Control的主要部件是一个Servlet: ActionServlet。这个servlet配置定义了一系列的ActionMapping。一个ActionMapping定义了一个路径,与输入请求的URI相对应,通常指定了一个Action类的类全名。所有的Action都是  [org.apache.struts.action. Action]的子类。Action封装了对业务逻辑类的调用,解释结果,最后将控制分发给合适的视图组件来创建响应。当框架转发给一个视图,实际上渲染视图是在他的范围之外了。
The framework also supports the ability to use ActionMapping classes that have additional properties beyond the standard ones required to operate the controller. This allows you to store additional information specific to your application and still utilize the remaining features of the framework. In addition, the framework lets you define logical "names" to which control should be forwarded so that an action method can ask for the "Main Menu" page (for example), without knowing the location of the corresponding JSP page. These features greatly assist you in separating the control logic (what to do) with the view logic (how it's rendered).
框架同样支持使用ActionMapping类,除了操作控制器的标准属性外它有额外的属性。这就容许你仍然使用框架的保留特征同时,来存储与你的应用相关的额外的信息。另外,框架让你定义逻辑名字给应该转交给那个控制,这样一个action方法被调用,例如在Main Menu页上。而不需要知道实际处理JSP页面的具体位置。这些功能使你能够分离控制逻辑(做什么)和表现逻辑(如果展示渲染)。
For more about the control layer, see the Building Controller Components chapter.
要更多了解关于控制层,参见Building Controller Components 章节。
1.3 Framework Control Flow
The framework provides several components that make up the Control layer of a MVC-style application. These include a controller component (servlet), developer-defined request handlers, and several supporting objects.
框架提供了几个组件来构成MVC风格应用的Control层。这些包括一个控制器组件(servlet),开发者定义的请求处理句柄,和几个支持对象。
The Struts Taglib component provides direct support for the View layer of a MVC application. Some of these tags access the control-layer objects. Others are generic tags found convenient when writing applications. Other taglibs, including JSTL, can also be used with the framework. Other presentation technologies, like Velocity Templates and XSLT can also be used with the framework.
Struts标签库组件提供了对MVC应用视图层的直接支持。其中一些tag访问控制层的对象。其他是一些书写应用时发现方便的通用标签。其他标签库,包括JSTL,也可以和这个框架一起使用。其他表现层技术,如Velocity Templates和XSLT也可以和框架一起使用。
The Model layer in a MVC application is often project-specific. The framework is designed to make it easy to access the business-end of your application, but leaves that part of the programming to other products, like JDBC, Enterprise Java Beans, Object Relational Bridge, or iBATIS, to name a few.
MVC应用中的模型层往往是和项目相关的。框架设计让他易于访问你应用的业务端,但把这一部分留给其他产品,如JDBC,EJB,ORB,iBATIS,及其他。
Let's step through how this all fits together.
让我们步步深入这些所有是如何组合起来的。
When initialized, the controller parses a configuration file (struts-config.xml) and uses it to deploy other control layer objects. Together, these objects form the Struts Configuration. The Configuration defines (among other things) the collection of ActionMappings [org.apache.struts.action.ActionMappings] for an application.
初始化时,控制器解析配置文件struts-config.xml使用它来发布其他控制层的对象。一起,这些对象从Struts配置中。配置定义了一个应用的ActionMapping的集合。
The controller component consults the ActionMappings as it routes HTTP requests to other components in the framework. Requests may be forwarded to JavaServer Pages or Action [org.apache.struts.action.Action] subclasses provided by the application developer. Often, a request is first forwarded to an Action and then to a JSP (or other presentation page). The mappings help the controller turn HTTP requests into application actions.
控制器对象咨询ActionMapping,当他路由HTTP请求到框架中其他组件时。请求被转发到JSP页面或者由应用开发人员定义的Action子类。通常,一个请求首先被转发到一个Action,接着是一个JSP(或其他表现页面)。这种映射帮助控制器将HTTP请求转换成应用程序的动作。
An individual ActionMapping [org.apache.struts.action.ActionMapping] will usually contain a number of properties including:
• a request path (or "URI"),
• the object type (Action subclass) to act upon the request, and
• other properties as needed.
一个单独的ActionMapping 通常包含几个属性包括:
 请求路径(URI)
 对象类型(Action 子类)来执行此请求
 其他所需要的属性
The Action object can handle the request and respond to the client (usually a Web browser) or indicate that control should be forwarded elsewhere. For example, if a login succeeds, a login action may wish to forward the request onto the mainMenu page.
Action对象可以处理请求并且响应客户端(一般是一个Web浏览器)或者指出控制应当转发到其他地方去。例如,如果一个登陆成功了,一个登陆action可能愿意转发请求到主菜单页面。
Action objects have access to the application's controller component, and so have access to that members's methods. When forwarding control, an Action object can indirectly forward one or more shared objects, including JavaBeans, by placing them in one of the standard contexts shared by Java Servlets.
Action对象可以访问应用的控制器组件,也可以访问这些组件的方法。当转发控制时,一个Action对象可以间接转发一个或多个共享对象,包括JavaBean,通过把它们放置在Java Servlet提供的多个标准环境之一。
For example, an Action object can create a shopping cart bean, add an item to the cart, place the bean in the session context, and then forward control to another mapping. That mapping may use a JavaServer Page to display the contents of the user's cart. Since each client has their own session, they will each also have their own shopping cart.
例如,一个Action对象可以创建一个购物筐Bean,在购物筐中加入一个条目,把bean放置到session环境中,然后转发控制到另一个映射。这个映射使用一个JSP页面来显示用户购物筐的内容。既然每个客户端有他们自己的session,那么他们也就有了他们自己的购物筐。
Most of the business logic in an application can be represented using JavaBeans. An Action can call the properties of a JavaBean without knowing how it actually works. This encapsulates the business logic, so that the Action can focus on error handling and where to forward control.
大多数应用程序的业务逻辑可以使用JavaBean来表示。一个Action可以直接调用一个JavaBean的属性,不需要知道它是如何实际工作的。这种封装了业务逻辑,使得Action可以集中精力处理错误和如何转发控制。
JavaBeans can also be used to manage input forms. A key problem in designing Web applications is retaining and validating what a user has entered between requests. You can define your own set of input bean classes, by subclassing ActionForm [org.apache.struts.action.ActionForm]. The ActionForm class makes it easy to store and validate the data for your application's input forms. The ActionForm bean is automatically saved in one of the standard, shared context collections, so that it can be used by other objects, like an Action object or another JSP.
JavaBean也被用来管理输入表单。在设计Web应用时,一个关键问题是在请求之间保持和验证用户输入的信息。你可以定义你自己的输入Bean类,继承自ActionForm。ActionForm类使得存储和校验你的应用程序的输入表单更加容易。ActionForm Bean在某个标准的,共享的容器集合众自动保存,这样它就可以被其他对象来使用,例如Action对象或者其他JSP。
The form bean can be used by a JSP to collect data from the user ... by an Action object to validate the user-entered data ... and then by the JSP again to re-populate the form fields. In the case of validation errors, the framework has a shared mechanism for raising and displaying error messages.
Form bean 可以用来在JSP上收集用户的信息。。。在Action里面验证用户输入信息。。。接着JSP再次重新生成form域。在验证发生错误时,框架有一个共享的机制,抛出和显示错误信息。
Another element of the Configuration are the ActionFormBeans [org.apache.struts.action.ActionFormBeans]. This is a collection of descriptor objects that are used to create instances of the ActionForm objects at runtime. When a mapping needs an ActionForm, the servlet looks up the form-bean descriptor by name and uses it to create an ActionForm instance of the specified type.
配置的另外一个元素是ActionFormBean。这是一个描述对象的集合,用来在运行时创建ActionForm的实例。当一个映射需要一个ActionForm时,servlet通过名字查询form-bean的定义描述,使用它来创建一个所需特定类型的ActionForm实例。
Here is the sequence of events that occur when a request calls for an mapping that uses an ActionForm:
当一个请求调用时,使用ActionForm来做映射时,发生的一系列的事件。
• The controller servlet either retrieves or creates the ActionForm bean instance.
• The controller servlet passes the bean to the Action object.
• If the request is being used to submit an input page, the Action object can examine the data. If necessary, the data can be sent back to the input form along with a list of messages to display on the page. Otherwise the data can be passed along to the business tier.
• If the request is being used to create an input page, the Action object can populate the bean with any data that the input page might need.

• 控制器servlet检索或者创建ActionForm bean对象.
• 控制器servlet将bean传递给Action对象.
• 如果请求被用来提交一个输入页面,Action对象可以检查数据。如果需要,数据被传回到输入表单,附加一个错误信息,可以显示在页面上。否则数据被传递给业务层。
• 如果请求用来创建一个输入页面,Action对象可以用输入页面可能用到的任何数据来创建bean对象。

The Struts Taglib component provides custom tags that can automatically populate fields from a JavaBean. All most JavaServer Pages really need to know is the field names to use and where to submit the form.
Struts Taglib组件提供客户化组件,可以从一个JavaBean自动生成域。几乎所有JSP页面实际上需要知道的是域名称和向哪里提交form.
Other tags can automatically output messages queued by an Action or ActionForm and simply need to be integrated into the page's markup. The messages are designed for localization and will render the best available message for a user's locale.
其他标签可以自动输出Action或者ActionForm排队的信息只需要简单的利用页面标记进行集成。信息被设计为本地化的,可以根据用户的local 来渲染最合适的信息。
The framework and Struts Taglib were designed from the ground-up to support the internationalization features built into the Java platform. All the field labels and messages can be retrieved from a message resource. To provide messages for another language, simply add another file to the resource bundle.
框架和Struts标签库从底层设计就支持Java平台内置的国际化特征。所有的字段标签 可以从一个message resource里面检索得到。要支持另外一种语言,只需要简单的将另外一个文件加到resource bundle中。
Internationalism aside, other benefits to the message resources approach are consistent labeling between forms, and the ability to review all labels and messages from a central location.
内置了国际化,其他好处包括各个form之间的消息资源访问是连续的,以及可以从一个中心位置来检查所有的标签和消息。
For the simplest applications, an Action object may sometimes handle the business logic associated with a request. However, in most cases, an Action object should invoke another object, usually a JavaBean, to perform the actual business logic. This lets the Action focus on error handling and control flow, rather than business logic. To allow reuse on other platforms, business-logic JavaBeans should not refer to any Web application objects. The Action object should translate needed details from the HTTP request and pass those along to the business-logic beans as regular Java variables.
对于最简单的应用,一个Action对象可能会处理请求关联的业务逻辑。然而,在大多数情况下,一个Action对象应该触发另外一个对象,使用JavaBean,来执行实际的业务逻辑。这使得Action集中处理错误处理和控制流,而不是业务逻辑。 为了容许其他平台的重用,业务逻辑JavaBean不应该指向任何其他Web 应用对象。Action对象可以传送所需要的细节信息,把他们当成日常的Java变量传递给业务逻辑bean。
In a database application, for example:
在一个数据库应用中,例如:
• A business-logic bean will connect to and query the database,
• The business-logic bean returns the result to the Action,
• The Action stores the result in a form bean in the request,
• The JavaServer Page displays the result in a HTML form.
• 一个业务逻辑应该连接和查询数据库,
• 业务逻辑bean返回结果给Action,
• Action将结果存储到request里面的一个form bean,
• JSP页面在一个HTML 页面中显示结果.
Neither the Action nor the JSP need to know (or care) from where the result comes. They just need to know how to package and display it.
无论Action或者JSP都不需要知道(或关心)结果从何而来。他们只需要知道如何包装和显示结果就可以了。
Other sections in this document cover the various framework components in greater detail. The Struts Taglib component includes several Developer Guides covering various aspects of the custom tags. A number of sample applications are bundled with the distribution that show how it all comes together.
这一文档的其他章节详细介绍了框架的不同组件。Struts标签库组件包括了多个开发者指南,包括了客户化组件的不同概念。发布版中包含了多个样例应用,显示了他们是如何组合工作的。
The framework is distributed under the Apache Software Foundation license. The code is copyrighted, but is free to use in any application.
框架按照Apache Software Foundation license规则发布。代码是有版权的,但那可以自由的用在任何应用中。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值