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

    xiaoxiao2021-03-26  22

    下午在做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文件内容

    示例:

    [html]  view plain  copy   <?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:

    [html]  view plain  copy   <?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:

    [html]  view plain  copy   <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!

    转载请注明原文地址: https://ju.6miu.com/read-660738.html

    最新回复(0)