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);

相关文章
|
7月前
|
JavaScript
Vue vue-config.js(字段属性详细介绍)
Vue vue-config.js(字段属性详细介绍)
62 2
|
3月前
|
Java API Nacos
spring.config.import 是一个 Spring Cloud Config Server 的属性,
spring.config.import 是一个 Spring Cloud Config Server 的属性,【1月更文挑战第25天】【1月更文挑战第123篇】
50 1
|
监控
SAP Spartacus cxFocus的config属性的赋值原理
SAP Spartacus cxFocus的config属性的赋值原理
107 0
SAP Spartacus cxFocus的config属性的赋值原理
SAP Spartacus config-initializer.service.ts get isStable属性失败的调试
SAP Spartacus config-initializer.service.ts get isStable属性失败的调试
103 0
SAP Spartacus config-initializer.service.ts get isStable属性失败的调试
|
.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应用程序的请求。
1026 0
|
1月前
|
Java 数据库连接 开发工具
web后端-SpringCloud-Config分布配置
web后端-SpringCloud-Config分布配置
|
2月前
|
API
在vite.config.js 配置代理
在vite.config.js 配置代理
63 2
|
2天前
|
JavaScript
vue.config.ts配置环境变量
vue.config.ts配置环境变量
10 0
|
27天前
|
移动开发 监控 小程序
mPaaS常见问题之uniapp ios端云打包的配置config文件如何解决
mPaaS(移动平台即服务,Mobile Platform as a Service)是阿里巴巴集团提供的一套移动开发解决方案,它包含了一系列移动开发、测试、监控和运营的工具和服务。以下是mPaaS常见问题的汇总,旨在帮助开发者和企业用户解决在使用mPaaS产品过程中遇到的各种挑战
22 0
|
30天前
|
消息中间件 SpringCloudAlibaba Java
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(八)Config服务配置+bus消息总线+stream消息驱动+Sleuth链路追踪
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(八)Config服务配置+bus消息总线+stream消息驱动+Sleuth链路追踪
772 0

热门文章

最新文章