问题是这样的, 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 元素,要系统正常运行能读取该配置文件,该怎么个 处理呢?求高手帮帮....

解决方案 »

  1.   


    在action元素增加自定义元素 set-property 元素,我看书上是有的,网上http://cxman.iteye.com/blog/714937 这也有相关介绍,可以我做的时候怎么,在读取配置文件时就出问题了,求求高手帮看看。
      

  2.   

    你的EmployeesActionMapping 中没有setLoginRequired方法。另外,也要检查struts-config.xml文件中className有没有写错,有没有在最前面多出一个空格之类的。