There is no Action mapped for namespace [/] and action name [hello] associated with context path [/d

下午在做struts2的demo时遇到以下问题:

There is no Action mapped for namespace [/] and action name [Login] associated with context path [/eprint]

错误

做如下检查:

1、确保struts.xml文件名大小写正确:struts.xml

2、确保struts.xml文件在src目录下(很重要!后面就着重说这个)

附:

web.xml文件内容

示例:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name></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.jsp</welcome-file>
  </welcome-file-list>
</web-app> 

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="default" namespace="/" extends="struts-default">
        <action name="LoginAction" class="com.xxx.control.LoginAction">
            <!-- 定义逻辑视图和物理资源之间的映射 -->
            <result name="error">index.jsp</result>
            <result name="success">/WEB-INF/main.jsp</result>
        </action>
    </package>
</struts>

index.jsp:

 <s:form action="LoginAction" namespace="/">
            <s:textfield name="username" label="username"></s:textfield>
            <s:password name="password" label="password"></s:password>
            <div id="login_button">
                <input type="submit" value="login"/> 
            </div>
            <div  id="register_button">
                <input type="button" value="register"/>
            </div>
 
       </s:form>


反复确认之后,还是没找到错误

找度娘,好多种解决方案,木有一个可以解决我的问题的

最后发现是我的struts.xml是在src目录下,没有任何疑问

但是我的编译后classes文件认却是在build目录下

不在WEB-INF下.......

这样它是找不到struts.xml文件的,报如上错误,也是情有可原的

 

最后,明确一点,struts.xm位于src下是为了编译后能找到struts配置文件,确保其在WEB-INF下才是根本!!!

更改eclipse web 项目认编译输出路径:

eclipse中只能针对项目更改,因为其认的是build目录下的,只能以项目更改:
项目右键 -》properties -》Java Build Path -》source -》Default output folder,选择你的路径,ok!

以上内容来源于百科书,可以关注我了解更多.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念