eclipse中配置struts2出現There is no Action mapped for namespace [/] and action name [Login] associated wi


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

示例:

[html]  view plain  copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="3.0"   
  3.     xmlns="http://java.sun.com/xml/ns/javaee"   
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
  6.     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  
  7.   <display-name></display-name>   
  8.     
  9.    <filter>  
  10.      <filter-name>struts2</filter-name>  
  11.      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
  12.   </filter>  
  13.   <filter-mapping>  
  14.      <filter-name>struts2</filter-name>  
  15.      <url-pattern>/*</url-pattern>  
  16.   </filter-mapping>  
  17.     
  18.   <welcome-file-list>  
  19.     <welcome-file>index.jsp</welcome-file>  
  20.   </welcome-file-list>  
  21. </web-app>   


struts.xml:

[html]  view plain  copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.3.dtd">  
  5. <struts>  
  6.     <package name="default" namespace="/" extends="struts-default">  
  7.         <action name="LoginAction" class="com.xxx.control.LoginAction">  
  8.             <!-- 定義邏輯視圖和物理資源之間的映射 -->  
  9.             <result name="error">index.jsp</result>  
  10.             <result name="success">/WEB-INF/main.jsp</result>  
  11.         </action>  
  12.     </package>  
  13. </struts>  


index.jsp:

[html]  view plain  copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. <s:form action="LoginAction" namespace="/">  
  2.         <s:textfield name="username" label="username"></s:textfield>  
  3.         <s:password name="password" label="password"></s:password>  
  4.         <div id="login_button">  
  5.             <input type="submit" value="login"/>   
  6.         </div>  
  7.         <div  id="register_button">  
  8.             <input type="button" value="register"/>  
  9.         </div>  
  10.   
  11.       </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!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM