1、web.xml
struts.properties
2、action 类名上加注解
多个Action
在类方法上加注解
- <!-- struts2 配置 -->
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- </filter-class>
- <init-param>
- <param-name>actionPackages</param-name>
- <param-value>com.yz.webapp.action</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
struts.properties
- #修改时重新加载
- struts.configuration.xml.reload = true
- #打印更多错误信息
- struts.devMode = true
- #注解扫描的包结尾名
- struts.convention.package.locators = action
- #映射扩展名
- struts.action.extension = html
- #结果资源所在路径
- #struts.convention.result.path = /WEB-INF/pages
2、action 类名上加注解
- @Namespace("/ssi")
- @ParentPackage("json-default")
- @Action(value = "admin", results = {
- @Result(name = "success", location = "/WEB-INF/pages/admin.jsp"),
- @Result(name = "json", type = "json", params = { "excludeProperties","adminMgr" }) })
- public class AdminAction extends BaseAction{}
多个Action
- @Namespace("/msa")
- @Result(name = "json", type = "json", params = { "excludeProperties",
- ".*Manager,.*\\.authorities,.*\\.roles,.*\\.fileCon" })
- @Actions(value = {
- @Action(value = "foreignship", results = { @Result(name = "success", location = "foreignship/foreignship.jsp") }),
- @Action(value = "foreignshipsee", results = { @Result(name = "success", location = "foreignship/foreignshipsee.jsp") }) })
- public class TMsaForeignShipArchivesAction extends BaseAction{}
在类方法上加注解
- //@Action(value = "add", results = { @Result(name = "success", location = "/index.jsp") })
- @Action(value = "save")
- public String save() {
- try{
- adminMgr.insert("insertYz_admin", admin);
- }catch(Exception e){
- msg = e.toString();
- success = false;
- }
- return this.SUCCESS;
- }