如何处理struts配置文件中action元素中的新自定义元素set-property
问题是这样的, struts 1.1版本,struts-config.xml文件中action元素中的新增加了自定义元素set-property元素,程序怎么个处理呢?各个文件如下:
-----------------------------------------
struts-config.xml
-----------------------------------------
...
<action
attribute="employeeForm"
input="/pages/addEmployee.jsp"
className=" com.employee.struts.usermapping.EmployeesActionMapping"
name="employeeForm"
path="/AddEmployee"
scope="request"
validate="true"
type="com.employee.struts.action.AddEmployeeAction">
<set-property property="loginRequired" value="true"/>
<!-- create a user define tag[set-property] for action tag -->
<forward name="error" path="/pages/addEmployee.jsp" />
<forward name="success" path="/EmployeeList.do" />
</action>
...
注意兰色 和 红色部分加了,系统就不能读取 struts 的配置文件,
----------------------------------------
EmployeeForm.java [formBean]
----------------------------------------
...
//import user define mapping class
import com.employee.struts.usermapping.*;
public class EmployeeForm extends ActionForm {
//....other method...
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
//-------------------------------------------------------------------------------
//KEY Question: 将参数mapping转化为自定义JAVA类能处理的mapping对象,目的是能识别并
//处理配置文件struts-config.xml中action元素中新增的自定义标签set-property元素;
//处理mapping对象的JAVA类继承了struts的ActionMapping对象同时新增加能处理自定义标签元素的代码
//-------------------------------------------------------------------------------
//EmployeesActionMapping employeesMapping=(EmployeesActionMapping)mapping;
//通过Action对象判断用户是否登录
//if(employeesMapping.isLoginRequired()){
HttpSession session=request.getSession();
if(session.getAttribute("USER")==null){
return null;
}
//}
if(roleid==null || roleid.length()==0){
errors.add("roleid",new ActionError("errors.roleid.required"));
}
if(depid==null || depid.length()==0){
errors.add("depid",new ActionError("errors.depid.required"));
}
...
}
}
--------------------------------------------
// EmployeesActionMapping.java
//------------------------------------------
package com.employee.struts.usermapping;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMappings;
/**
*
* 功能:(TN)为struts的配置文件(struts-config.xml)中含有自定义子元素[如set-property元素]的action元素定义一个
* 处理mapping映射的类
*/
public class EmployeesActionMapping extends ActionMapping {
//增加对配置文件struts-config.xml中的action元素中的自定义子标签
//<set-property property="loginRequired" value="true"/>
//进行处理的对应类文件
private boolean loginRequired=true; //default need to check login flag
public boolean isLoginRequired(){
return this.loginRequired;
}
}
//---------------------------------------------
参考: http://cxman.iteye.com/blog/714937
问题是:
在配置文件中注意兰色 和 红色部分加了,系统就不能读取 struts 的配置文件,去掉兰色部分,也不能读取struts配置文件,红色和兰色部分都去掉则可以正常读取;如果要求在配置文件中的action元素新增加了 set-property 元素,要系统正常运行能读取该配置文件,该怎么个 处理呢?求高手帮帮....