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;
}
}