最近刚刚接触struts,写了一小段代码测试,结果tom老是报404错误
HTTP Status 404 - There is no Action mapped for action name login.
type Status report
message There is no Action mapped for action name login.
description The requested resource is not available.
Apache Tomcat/7.0.39
检查半天没发现错误,极其郁闷,最终在复查struts.xml文件时发现问题,原码如下:<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="com.message.action" namespace="action" extends="struts-default">
<action name="login" class="com.message.action.login">
<result name="success" type="dispatcher">
/WEB-INF/main.jsp
</result>
</action>
</package>
</struts>
原来是namespace前面少了“/”更正如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="com.message.action" namespace="/action" extends="struts-default">
<action name="login" class="com.message.action.login">
<result name="success" type="dispatcher">
/WEB-INF/main.jsp
</result>
</action>
</package>
</struts>
问题终于得到解决!