日期:2014-05-18  浏览次数:20698 次

求助:Struts开发web应用时报错:Cannot retrieve mapping for action
javax.servlet.ServletException:   Cannot   retrieve   mapping   for   action

这是为什么?

jsp文件中的   <html:form   action= "*.do "> 中的action值到底对应配

置文件struts-config.xml中mapping元素中的哪个值?


谢谢!




------解决方案--------------------
给你个sample:

struts-config.xml:

<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN " "http://struts.apache.org/dtds/struts-config_1_2.dtd ">

<struts-config>
<data-sources />

<form-beans>

<form-bean name= "LoginBean " type= "FormBean.LoginBean ">
<form-property name= "userId " type= "java.lang.Integer "/>
<form-property name= "password " type= "java.lang.String "/>
</form-bean>

</form-beans>

<global-exceptions />
<global-forwards />
<action-mappings >

<action-mapping>
<action path= "/Login " name= "LoginBean " type= "ActionHandle.LoginAction " scope= "session " validate= "true ">
<forward name= "loginSuccess " path= "/LoginSuccess.jsp " />
<forward name= "loginFailed " path= "/LoginFailed.jsp " />
</action>


</action-mappings>

<message-resources parameter= "com.yourcompany.struts.ApplicationResources " />
</struts-config>


在LoginAction里面再根据情况转发就可以了,
------解决方案--------------------
借用一下楼上的代码
<action path= "/Login " name= "LoginBean " type= "ActionHandle.LoginAction " scope= "session " validate= "true ">
<forward name= "loginSuccess " path= "/LoginSuccess.jsp " />
<forward name= "loginFailed " path= "/LoginFailed.jsp " />
</action>
匹配这里的 path= "/Login " 的path