一、Struts的Action的一些属性的具体意思?

Struts中Action的一段定义如下

<action>

attribute="aaForm"

input="/aa.jsp"

name="aaForm"

path="/aa"

scope="request"

type="com.yourcompany.struts.action.AaAction">

<forward name="aa" path="/aa.jsp" />

</action>

其中的attribute和name是什么意思代表什么、<forward name="aa" path="/aa.jsp" />这个中的name又代表什么、转发的名字吗?

Action能转发多个jsp吗?正确一个、错误的时候转给另一个。应该怎么写

二、struts-config.xml文件

/*

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>

<data-sources />

<form-beans >

    <form-bean name="userForm" type="cn.hxex.sample.struts.form.UserForm" />

</form-beans>

<global-exceptions />

<global-forwards />

<action-mappings >

    <action

      attribute="userForm"

      input="/form/user.jsp"

      name="userForm"

      path="/user"

      scope="request"

      type="cn.hxex.sample.struts.action.UserAction" >

      <forward name="success" path="/success.jsp" />

    </action>

</action-mappings>

<message-resources parameter="cn.hxex.sample.struts.ApplicationResources" />

</struts-config>

*/

三、Struts中Action的属性详解

/*

attribute:指定ActionForm保存到指定上下文所使用的属性名,如果不指定attribute属性值,

将使用name属性值作为保存时的属性名。即attribute的默认值就是name属性值。

input: 该Action中相关ActionForm获取用户输入的输入页面,当将ActionForm设为自动验证输入数据,发现不合法数据返回错误时,将返回该页面    

name: 当前Action中用到的ActionForm的名字,其具体信息在配置文件其他地方另有详细定义

scop:指定保存ActionForm上下文的范围。即Action中所用到的ActionForm的生存期,可以为“request”或“session”,随着生存期的设置,该Action也会在相应的时间被创建    

validate:如果本属性为true则在Action动作之前其对应的ActionForm的validate方法会自动被调用,一般用以验证用户输入的数据    

forward:设置处理用户请求的serverlet或其它资源如Jsp页面等。如指定了这属性则type属性就会失去作用

严格来说<forward,include,type>属性应该使用且只使用其中的一个。 这属性用于跳转到另一个非Action处理程序中。

unknown: 如果将该属性设置为true,那么就是声明这个Action将处理整个应用中所有未找到相应处理Action的请求,当然,一个应用系统中也只会有一个Action的unknown属性可以设为true    

Prefix:用来匹配请求参数与bean属性的前缀  

Suffix: 用来匹配请求参数与bean属性的后缀  

*/

与scope有关,比如scope="request" 时,可以通过request.getAttribute(attribute的值)来获取Form对象

而name对应于前面form的定义。forward 中的name可以说是页面的一个别名,转发时根据名字就行了

可以转发多个,如定义了两个forward success和error

<forward name="success" path="/aa.jsp" />

<forward name="error" path="/bb.jsp" />

try

{

……

}

catch(Exception)

{

……

return mapping.findFord("error");

}

return mapping.findFord("success");

posted on 2013-11-28 22:36  JAVA创世人  阅读(1268)  评论(0编辑  收藏  举报