下午在eclipse中配置struts2時報:
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!
