听说struts2在现在已经不流行了,但作为入门的菜鸟还是学一下,这不,就出现了这个问题了。
There is no Action mapped for namespace [/] and action name [Login] associated
这问题的出现是由于配置或者自己书写搞错问题,我的就是配置问题1、要确保struts.xml文件在src目录下
2、struts.xml:和web.xml里的配置没问题。
struts.xml配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8" />
<package name="helloPkg" namespace="/" extends="struts-default">
<action name="hello" class="itxiaolong.com.HelloAction" method="sayHello">
<result name="SUCCESS">/hello.jsp</result>
</action>
</package>
</struts>
web.xml配置如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>weixin203</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
确保那两个条件没错但依然报错的话就得注意了。这个很大可能就是其他配置问题,也就是路径问题。
一般编译后classes文件默认却是在build目录下,而不在WEB-INF下,那么编译器是找不到struts.xml文件的
所以要设置一下编译后文件目录路径。
项目右键 -》properties -》Java Build Path -》source -》,按下图操作
之后重新启动tomcat即可正常访问。