struts2中怎么实现在struts.xml配置文件的action标签中加入自定义属性
struts2中如何实现在struts.xml配置文件的action标签中加入自定义属性?
这是一个struts2中struts.xml配置文件的action标签: <action name="test" class="test"> ,如果我要加入
一个自定义的属性例如: <action name="test" class="test" mytype="haha"> , 显然应用程序启动时会异常,
如何来实现呢?
package com.opensymphony.xwork2.config.entities下的ActionConfig类,定义了action的:
protected List <InterceptorMapping> interceptors;
protected Map <String, Object> params;
protected Map <String, ResultConfig> results;
protected List <ExceptionMappingConfig> exceptionMappings;
protected String className;
protected String methodName;
protected String packageName;
我想做的就是在这里加上一个String mytype,我用自己的类继承了ActionConfig类做了扩展.
然后呢,几个使用到这个ActionConfig的类,我也用自己的类了.问题现在出现在这里:
package org.apache.struts2.config 包下的class Settings中的这个方法:
private static Settings getDefaultInstance() {
if (defaultImpl == null) {
// Create bootstrap implementation
defaultImpl = new DefaultSettings();
// Create default implementation
try {
String className = get(StrutsConstants.STRUTS_CONFIGURATION);
if (!className.equals(defaultImpl.getClass().getName())) {
try {
// singleton instances shouldn't be built accessing request or session-specific context data
defaultImpl = (Settings) ObjectFactory.getObjectFactory().buildBean(Thread.currentThread().getContextClassLoader().loadClass(className), null);
} catch (Exception e) {
LOG.error("Settings: Could not instantiate the struts.configuration object, substituting the default implementation.", e);
}
}
} catch (IllegalArgumentException ex) {
// ignore
}
}
return defaultImpl;
}
问题在这里:
defaultImpl = (Settings) ObjectFactory.getObjectFactory().buildBean(Thread.currentThread().getContextClassLoader().loadClass(className), null);
类型转换错误,defaultImpl为settings,后面一个到底要怎搞啊?
这是一个struts2中struts.xml配置文件的action标签: <action name="test" class="test"> ,如果我要加入
一个自定义的属性例如: <action name="test" class="test" mytype="haha"> , 显然应用程序启动时会异常,
如何来实现呢?
package com.opensymphony.xwork2.config.entities下的ActionConfig类,定义了action的:
protected List <InterceptorMapping> interceptors;
protected Map <String, Object> params;
protected Map <String, ResultConfig> results;
protected List <ExceptionMappingConfig> exceptionMappings;
protected String className;
protected String methodName;
protected String packageName;
我想做的就是在这里加上一个String mytype,我用自己的类继承了ActionConfig类做了扩展.
然后呢,几个使用到这个ActionConfig的类,我也用自己的类了.问题现在出现在这里:
package org.apache.struts2.config 包下的class Settings中的这个方法:
private static Settings getDefaultInstance() {
if (defaultImpl == null) {
// Create bootstrap implementation
defaultImpl = new DefaultSettings();
// Create default implementation
try {
String className = get(StrutsConstants.STRUTS_CONFIGURATION);
if (!className.equals(defaultImpl.getClass().getName())) {
try {
// singleton instances shouldn't be built accessing request or session-specific context data
defaultImpl = (Settings) ObjectFactory.getObjectFactory().buildBean(Thread.currentThread().getContextClassLoader().loadClass(className), null);
} catch (Exception e) {
LOG.error("Settings: Could not instantiate the struts.configuration object, substituting the default implementation.", e);
}
}
} catch (IllegalArgumentException ex) {
// ignore
}
}
return defaultImpl;
}
问题在这里:
defaultImpl = (Settings) ObjectFactory.getObjectFactory().buildBean(Thread.currentThread().getContextClassLoader().loadClass(className), null);
类型转换错误,defaultImpl为settings,后面一个到底要怎搞啊?
1 楼
cscs31
2008-01-14
为什么要加这个?
2 楼
wwwcom
2008-05-15
呵呵,建议不要加了,我们公司前段时间有这样的需求,结果越弄越复杂,Struts2的有些类是私有或者受保护的,所以有些类不能继承(除非你的包名和他的一样),到最后没有办法实现了.最后直接改的struts2的源码来实现.