struts.properties
struts.action.extension=
struts.mapper.class=org.apache.struts2.dispatcher.mapper.Restful2ActionMapper
struts.enable.SlashesInActionNames=true
web.xml
<display-name>Struts2 test</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/app/*</url-pattern>
</filter-mapping>
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>
<include file="test.xml"/>
<!-- Add packages here -->
</struts>
test.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="com" namespace="/app" extends="struts-default">
<action name="test/*" class="com.test.HelloWorld">
<param name="message">{1}</param>
<result>/test/success.jsp</result>
</action>
</package>
</struts>
类:
package com.test;
public class HelloWorld extends BaseActionSupport {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String execute() throws Exception {
return "success";
}
public String view()throws Exception{
return "success";
}
}