There is no Action mapped for namespace [/] and action name [test] associated with context path [...
阿新 • • 發佈:2018-12-20
There is no Action mapped for namespace [/] and action name [test] associated with context path [/s2d]. - [unknown location]
stucts2中錯誤 找不到檔案路徑
可能性:
structs.xml 檔案(檔名一個字母都不能出錯)應該放在 src資料夾下面。具體配置如下:
<?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"> <!-- START SNIPPET: xworkSample --> <struts> <!-- extends必須寫,直接或者間接繼承struts-default name自定義 --> <package name="struts" extends="struts-default"> <!-- name是請求名稱,不要寫/;class對應action完全限定名=包名+類名 method: 指定處理類所觸發的方法 --> <action name="test" class="com.wang.struts2.Test"> <!-- result是結果集 name和對應action中的方法的返回值匹配,預設是success --> <result name="success">/MyJsp.jsp</result> </action> </package> </struts>
配置中的extends="struts-default" 必須寫不能錯(當然也可以間接繼承)
web.xml(在WEB-INF資料夾下) <filter-name>struts2</filter-name> 這個不能寫錯切記勿寫成structs2
<?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"> <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>*.action</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
處理類(此處不多說)
package com.wang.struts2;
import com.opensymphony.xwork2.Action;
public class Test {
public String execute(){
System.out.println("hello Test");
return Action.SUCCESS;
}
}