struts2配置常见错误——(一)不能处理错误Struts has detected an unhandled exception:

本文解析了Struts2框架中Action配置错误的原因及解决办法,包括路径配置错误导致的无法实例化Action等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Messages:
1.cn.itcast.action.CustomerAction
2.Unable to instantiate Action, cn.itcast.action.CustomerAction, defined for 'CustomerAction' in 
    namespace '/'cn.itcast.action.CustomerAction
File:
org/apache/catalina/loader/WebappClassLoader.java
Line number:
1,718

Stacktraces
Unable to instantiate Action, cn.itcast.action.CustomerAction, 
    defined for 'CustomerAction' in namespace '/'cn.itcast.action.CustomerAction - 
    action - file:/D:/develop/apache-tomcat-7.0.52/apache-tomcat-7.0.52/webapps/crm_ssh/WEB-INF/classes/struts.xml:12:88

找到一个不能处理的问题,不能展示action,这个问题是在struts.xml中,一般是文件的路径配置上除了错误

例如在如下程序过程中由于路径写错就会报这个错误:

<action name="CustomerAction_*" class="cn.shop.action.CustomerAction" method="{1}"></action>

把class属性更正为:

<action name="CustomerAction_*" class="cn.shop.web.action.CustomerAction" method="{1}"></action>

就可以了!

2,再比如:

Messages:	·  There is no Action mapped for namespace [/crm] and action name [CustomerAction] associated with context path [/crm_ssh].

Stacktraces
There is no Action mapped for namespace [/crm] and action name [CustomerAction] associated with context path [/crm_ssh]. - [unknown location] 

这个是一个路径书写错误,struts2很委婉的表达了404的错误,大概意思是在/crm下没有找到想要的action,实际上根本没有配置/crm路径,crm只是一个包名而已,和路径无关,错误认识的代码:

<package name="crm" extends="struts-default" namespace="/">
<action name="CustomerAction_*" class="cn.itcast.web.action.CustomerAction" method="{1}">

这个路径访问的路径应该是:http://localhost:8080/项目名称/CustomerAction_*

如果CustomerAction_中只有一个execute方法,直接访问:http://localhost:8080/项目名称/CustomerAction也可以









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值