struts2種出現的There is no Action mapped for namespace [/] and action name 錯誤

今天在調試一個基礎的Struts2框架小程序。總是提示"There is no Action mapped for namespace / and action name"的錯誤。上網查詢後發現這是一個初學者經常碰到的問題,導致錯誤的原因主要有兩種。總結如下:

      一、struts.xml文件錯誤。這種錯誤又分爲以下幾種:1,struts.xml文件名錯誤。一定要注意拼寫問題;2,struts.xml文件放置路徑錯誤。一定要將此文件放置在src目錄下。編譯成功後,要確認是否編譯到classes目錄中;3,struts.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>
複製代碼

 

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


原網站:http://www.cnblogs.com/gulvzhe/archive/2011/11/21/2256632.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章