錯誤There is no Action mapped for namespace / and action name—Struts2

來源:互聯網
上載者:User

標籤:style   blog   class   code   java   ext   

Struts2出現錯誤,總是提示"There is no Action mapped for namespace / and action name"的錯誤。

錯誤碼如下:

09:36:13,515 WARN  [Dispatcher] Could not find action or resultThere is no Action mapped for namespace [/] and action name [css] associated with context path [/ChinaUnicom]. - [unknown location]    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)    at java.lang.Thread.run(Thread.java:619)

上網查詢後發現這是一個初學者經常碰到的問題,導致錯誤的原因主要有兩種。總結如下:

     1.struts.xml檔案錯誤。這種錯誤又分為以下幾種:

1.1struts.xml檔案名稱錯誤。一定要注意拼字問題;

1.2struts.xml檔案放置路徑錯誤。一定要將此檔案放置在src目錄下。編譯成功後,要確認是否編譯到classes目錄中;

1.3struts.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>    <package name="default" namespace="/" extends="struts-default">        <action name="login" class="com.wanggc.struts2.sample.Struts2Action">        <result name="success">/jsp/result.jsp</result>        </action>    </package></struts>

 

2.如果排除了struts.xml檔案的問題,還有一種可能就是,在web.xml檔案中的<welcome-file>資訊中是否配置了自己工程的啟動頁面。如果沒有配置,地址欄中要輸入完成的url,如:http://localhost:8080/Struts2Sample/jsp/login.jsp,後面的資來源詳細資料不輸入的時候也會報這個錯誤,我就是栽在這個問題上的(^_^)。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.