解决STRUTS2 错误 There is no Action mapped for namespace / and action name login
这个错误就是因为找不到对应的action造成的;
解决方法:
1)检查JSP文件中的form的action属性的值是否正确;
<form action="login.action" method="post">
2)检查web.xml文件中的<url-pattern>标签的值的类型:若为/*,则JSP文件中form的action属性的值为xxx.action;若为*.do,则JSP文件中form的action属性的值为xxx.do;
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2 </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>struts2 </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping>
</web-app>
3)看struts.xml文件是否在SRC文件下,只有在SRC文件下才能保证编译后的struts.xml文件会在web-inf/classes文件中;
同时struts2只会默认加载struts.xml文件不会加载如struts2.xml文件,若名称不是struts.xml的文件要在web.xml中配置;
<filter>
<filter-name>struts2 </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
<init>
<param-name>config</param-name>
<param-value>struts2.xml,struts-default.xml,struts-plugin.xml</param-value>
</init>
</filter>
4)若以上均没问题则要仔细检查拼写是否出错。