struts-config中action的attribute属性与name属性的关系

简介: 1、在一般情况下,actionForm是被存储在一定的scope中(request或session,通过action的scope属性来配置),当我们在配置时,指定name而不指定attribute,那么指定的name值就作为actionForm存储在scope中的key值,我们可以在action中通过httpServletRequest.getAttribute("指定的name属性值")来获
1、在一般情况下,actionForm是被存储在一定的scope中(request或session,通过action的scope属性来配置),当我们在配置时,指定 name而不指定 attribute,那么指定的 name值就作为actionForm存储在scope中的key值,我们可以在action中通过httpServletRequest.get Attribute("指定的 name属性值")来获得这个actionForm;   当我们既配置了 name又配置了 attribute,那么actionForm存储在scope中的key值就采用 attribute属性指定的值了,这时要通过httpServletRequest.get Attribute("指定的 attribute属性值")来获得actionForm,此时通过httpServletRequest.get Attribute("指定的 name属性值")是不能获得actionForm的。  
   
  所以,是否配置 attribute属性就决定了actionForm存储在scope中的key值是采用 name,还是采用 attribute

 2、 在《Programming Jakarta Struts》这本书中的第四章“Configuring the Struts Application”中这样一段说明来分别阐述这两
个属性:(102页)
++++++++
atribute:
++++++++
The name of the request or session scope attribute under which the form bean for this action can be accessed.
A value is only allowed here if there is a form bean specified in the name attribute. This attribute is
optional and has no default value.

++++++++
name:
++++++++
The name of the form bean, if any, that is associated with this action. This value must be the name attribute
from one of the form-bean elements defined earlier. This attribute is optional and has no default value.

最初看这些真的还是不好区分这两者。不过在仔细看过struts的源代码以后,豁然开朗。。。

下面主要对attribute进行解释,应为没有人会对name属性不了解的(呵呵。。。)


解释:在struts实例化actionform的时候,有两种情况:如果已经存在,那么从内存中取回;如果第一次实例化,那么创建,并放入内存。
这样就有一个问题了,struts是根据什么来取回并创建actionform的呢,答案就是attribute的值。让我们进入struts的源代码:

/**
*创建或者取回formbean方法
*该方法在:org.apache.struts.util.RequestUtils中
*/
public static Actionform createActionform(
HttpServletRequest request,
ActionMapping mapping,
ModuleConfig moduleConfig,
ActionServlet servlet) {
。。。。
。。。
// Is there a form bean associated with this mapping?
//得到action mapping中attribute的值
String attribute = mapping.getAttribute();
。。。。
。。。。
Actionform instance = null;
HttpSession session = null;
//yes!!就在这里了,把创建以后的actionform放在request或者session里,看到放入的名字了么,就是mapping.getAttribute();
if ("request".equals(mapping.getScope())) {
instance = (Actionform) request.getAttribute(attribute);

相关文章
|
JavaScript
Vue vue-config.js(字段属性详细介绍)
Vue vue-config.js(字段属性详细介绍)
214 2
|
监控 Dubbo 搜索推荐
No application config found or it‘s not a valid config! Please add <dubbo:application name=“...“ />
No application config found or it‘s not a valid config! Please add <dubbo:application name=“...“ />
1609 1
|
Java API Nacos
spring.config.import 是一个 Spring Cloud Config Server 的属性,
spring.config.import 是一个 Spring Cloud Config Server 的属性,【1月更文挑战第25天】【1月更文挑战第123篇】
2189 1
|
.NET 开发框架
web.config中httpRunTime的属性(转)
配置httpRuntime也可以让FileUpload上传更大的文件,不过设置太大了会因用户将大量文件传递到该服务器而导致的拒绝服务攻击(属性有说明) 参考网站:http://blog.csdn.net/wygyhm/article/details/2819388   3>网友“@@”提示是httpRuntime问题(谢谢他):      问题解决方法:在web.config中的内加入如下代码:        4>来自MSDN解释:     httpRuntime是配置asp.net http运行时设置,以确定如何处理对asp.net应用程序的请求。
1124 0
|
12月前
|
算法 安全 Java
微服务(四)-config配置中心的配置加解密
微服务(四)-config配置中心的配置加解密
|
12月前
|
JavaScript
Vue3基础(19)___vite.config.js中配置路径别名
本文介绍了如何在Vue 3的Vite配置文件`vite.config.js`中设置路径别名,以及如何在页面中使用这些别名导入模块。
488 0
Vue3基础(19)___vite.config.js中配置路径别名
|
移动开发 JavaScript 前端开发
UniApp H5 跨域代理配置并使用(配置manifest.json、vue.config.js)
这篇文章介绍了在UniApp H5项目中处理跨域问题的两种方法:通过修改manifest.json文件配置h5设置,或在项目根目录创建vue.config.js文件进行代理配置,并提供了具体的配置代码示例。
UniApp H5 跨域代理配置并使用(配置manifest.json、vue.config.js)
|
JSON 前端开发 JavaScript
vue.config.js配置详解
【8月更文挑战第16天】vue.config.js配置详解
712 1
vue.config.js配置详解
|
11月前
|
JavaScript 前端开发 应用服务中间件
vue前端开发中,通过vue.config.js配置和nginx配置,实现多个入口文件的实现方法
vue前端开发中,通过vue.config.js配置和nginx配置,实现多个入口文件的实现方法
576 0
|
11月前
|
前端开发 JavaScript
vite vue3 config配置
【10月更文挑战第5天】
464 0