`

struts多模块配置文件所碰到的异常

阅读更多

 昨天晚上碰到一个问题,如下:


今天早上起来,终于弄明白了。

下面说说原因:

 

 问题出在了 struts-config-role.xml 与 struts-config-user.xml 中

    struts-config-role.xml

<struts-config>
 
 <!-- ================================================ Form Bean Definitions -->
    <form-beans>
     
     	<!-- "RoleForm" action -->
     	<form-bean name="roleForm"
          	                    type="com.nana.web.struts.forms.RoleForm">
     	</form-bean>
     
     </form-beans>
<!-- =========================================== Action Mapping Definitions -->
    <action-mappings>
   
  	<!-- "UpdateRole" action -->
  	<action path=" /role/updateRole"
          	             type="com.nana.web.struts.actions.UpdateRoleAction"
                             scope="request"
                             name="roleForm"
                             attribute="roleForm"
                             validate="true"
                             input="/role/updateRole.jsp">
                	<forward name="SUCCESS" path="/role/result/updateRole_success.jsp"></forward>
                 </action>
   
    </action-mappings>
</struts-config>

 

    struts-config-user.xml

   

<struts-config>
 
 <!-- ================================================ Form Bean Definitions -->
    <form-beans>
     
     	<!-- "UserForm" action -->
     	<form-bean name="userForm"
          	                    type="com.nana.web.struts.forms.UserForm">
     	</form-bean>
     
     </form-beans>
<!-- =========================================== Action Mapping Definitions -->
    <action-mappings>
   
  	<!-- "UpdateRole" action -->
  	<action path="role/updateRole"
          	             type="com.nana.web.struts.actions.UpdateUserAction"
                             scope="request"
                             name="userForm"
                             attribute="userForm"
                             validate="true"
                             input="/user/updateUser.jsp">
                	<forward name="SUCCESS" path="/user/result/updateUser_success.jsp"></forward>
                 </action>
   
    </action-mappings>

 原来是两个path属性的值完全相同了,那么前边配置的那个就不会生效,也就是说,当客户端的请求路径是 /role/updateRole.do 的时候,只会是匹配 com.nana.web.struts.actions.UpdateUserAction 的实例,这对于 User模块 来说不会有任何问题(歪打正着),但对于 Role模块 来说就麻烦了,

此时UserForm 被错误地指定给了它(本来应该有自己的RoleForm),所以产生了一开头时图片上的异常。

 

也是,action 标签的 path属性本来就应该是唯一的,这是最基本的,无论是不是分了模块,写下来记录一下。。。

  • 大小: 78.5 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics