web.xml配置
<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>/*</url-pattern>
</filter-mapping>
jar包:
1.commons-fileupload-1.2.2.jar
2.commons-io-1.3.2.jar
3.freemarker-2.3.15.jar
4.ognl-3.0.1.jar
5.struts2-convention-plugin-2.2.3.jar
6.struts2-core-2.2.3.jar
7.xwork-core-2.2.3.jar
struts.xml
<include file="struts/*.xml"></include>
<constant name="struts.mapper.class"
value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper" />
<constant name="struts.mapper.prefixMapping" value="/p:rest,/s:rest,:struts" />
<constant name="struts.rest.namespace" value="" />
<!-- 指定控制器类的后缀为Controller -->
<constant name="struts.convention.action.suffix" value="Controller" />
<constant name="struts.convention.action.mapAllMatches" value="true" />
<!-- 指定Action所在包继承的父包 -->
<constant name="struts.convention.default.parent.package"
value="rest-default" />
源文件实例:
@ResultPath("/")
@Results({@Result(name = "error", location = "/admin/error.jsp", type = "redirect"),
@Result(name = "findInfo", location = "/admin/advert/listAdvert.jsp"),
@Result(name = "addAdvert", location = "/admin/advert/addAdvert.jsp"),
@Result(name = "modifyAdvert", location = "/admin/advert/addAdvert.jsp"),
@Result(name = "result", location = "/admin/result.jsp"),})
public class AdvertAction extends BaseAction {
@Action(value = "/admin/advert/find")//表单action属性=/admin/advert/find.action
public String find(){
return "findInfo";
}
@Action(value = "/admin/advert/add")
public String add(){
return "addAdvert";
}
}