web.xml:
<!-- struts 配置 -->
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts.xml:
<?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">
<constant name="struts.devMode" value="true" /><!-- 开发模式 -->
<constant name="struts.i18n.encoding" value="UTF-8" /><!-- Web运用编码 -->
<!-- 搜索视图资源的路径 -->
<constant name="struts.convention.result.path" value="/WEB-INF/jsp/" />
<!-- Action类名分隔符 -->
<constant name="struts.convention.action.name.separator" value="_" />
<!-- convention类重加载 -->
<constant name="struts.convention.classes.reload" value="true" />
<!-- Action后缀名 -->
<constant name="struts.convention.action.suffix" value="Action" />
<constant name="struts.action.extension"
value="action,do,html,htm,php,aspx" /><!-- Action扩展名 -->
<constant name="struts.convention.package.locators"
value="web,action" /><!-- 搜索Action资源的包路径 -->
action:
package my.demo.web.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport{
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("hello world");
return SUCCESS;
}
}
报错内容:
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
There is no Action mapped for namespace [/] and action name [hello_world] associated with context path [/DemoConvention].
Stacktraces
There is no Action mapped for namespace [/] and action name [hello_world] associated with context path [/DemoConvention]. - [unknown location]