以下几点是网上的一些关于attribute的解释:
1)应用前提,attribute只有在设置了name后才有意义。
2)attribute可以实现对象的重用,即如果设置了attribute属性,在创建actionform是,会先去查找相应的scope中是否有此对象,如果有,则重用,否则创建新的对象。
3)当你将创建的acitonForm保存到相应的scope(默认是保存在session中)中时,你想用一个更有意义的名字来访问它时,它就有意义了。
例如:
<action
attribute="newUserLoginForm"
name="userLoginForm"
type="userLoginAction"
scope="request"
path="/login">
在struts实例化actionform的时候,struts是根据attribute的值来查找并创建actionform,有两种情况:如果已经存在,那么从内存中取回;如果第一次实例化,那么创建,并放入内存。
看一下org.apache.struts.util.RequestUtils中的源代码
public static Actionform createActionform(HttpServletRequest request,
ActionMapping mapping, ModuleConfig moduleConfig,
ActionServlet servlet) {
/*
* 此处省略一些源代码
*/
String attribute = mapping.getAttribute();
/*
* 此处省略一些源代码
*/
Actionform instance = null;
HttpSession session = null;
if ("request".equals(mapping.getScope())) {
instance = (Actionform) request.getAttribute(attribute);
} else {
session = request.getSession();
instance = (Actionform) session.getAttribute(attribute);
}
/*
* 此处省略一些源代码
*/
}
如果没有配置attribute属性的话, struts才会从name属性里读出要创建的formbean 的名字,并创建一下实例,看下边的源代码就知道了
org.apache.struts.config.ActionConfig
protected String attribute = null;
public String getAttribute() {
// 注意这个地方
if (this.attribute == null) {
return (this.name);
} else {
return (this.attribute);
}
}
public void setAttribute(String attribute) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.attribute = attribute;
}
分享到:
相关推荐
DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources> <data-...
<struts-config> <data-sources /> <form-beans > <form-bean name="addForm" type="com.lmf118.struts.form.AddForm" /> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings > ...
<struts-config> <form-beans> <form-bean name="LoginForm" type="com.yza.struts.form.LoginForm"></form-bean> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings> <action ...
<struts-config> <data-sources /> <form-beans > <form-bean name="testForm" type="com.yourcompany.struts.form.TestForm" /> <form-bean name="test1Form" type="com.yourcompany.struts.form.Test1Form" />...
<action attribute="loginForm" input="/login.jsp" name="loginForm" path="/login" scope="request" type="test.action.LoginAction"> </action> </action-mappings> <message-resources parameter="test....
2.struts-config.xml文件配置 <form-beans> <form-bean name="actionForm" type="org.apache.struts.action.DynaActionForm"> <form-property name = "filedata" type = "org.apache.struts.upload.FormFile" /...
SQL server data type mappings
同加载struts方式类似,选择Myeclipse后在弹出的二级菜单中选择Add spring in action in action Capabilities…后提示如下图所示: 选择所需要的spring in action in action包,然后默认下一步,直到完成。 到此...
ODBC data type mapping
Efficient SPARQL-to-SQL with R2RML Mappings
2. ActionSevlet首先调用struts配置文件(struts-config.xml),如果有表单提交,需要自动填充ActionForm Bean(找struts配置文件的<form-beans>),根据请求分派给相应的Action(找struts配置文件的<action-mappings>...
RegUserForm "/> </form-beans> <br/><action-mappings> <action path="/regUserAction" type=" org.cjea.Struts.example.RegUserAction " attribute=" regUserForm " scope="request...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
Convergence of general algorithm for I-generalized asymptotically nonexpansive nonself-mappings in uniformly convex hyperbolic spaces
标签:airavata-rest-mappings-0.9-javadoc.jar,airavata,rest,mappings,0.9,javadoc,jar包下载,依赖包
标签:airavata-rest-mappings-0.7.jar,airavata,rest,mappings,0.7,jar包下载,依赖包
标签:airavata-rest-mappings-0.8.jar,airavata,rest,mappings,0.8,jar包下载,依赖包
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
Rapture.zip,无效的
DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="erpweb" extends="struts-default"> ...