慕村225694
struts中采用注解配置Action需要导入struts2-convention-plugin的jar包 Action 省略getters和setters@ParentPackage("xystruts-default")@Namespace("/login")public class LoginAction extends BaseAction{ private String verifyCode; @Action(value = "login", results = { @Result(location = "/pages/main.jsp"), @Result(name = "login", location = "/pages/login.jsp") }) public String login() { String sysVerifyCode = (String) getSession().get("verifyCode"); if (StringHelper.isEmpty(verifyCode) || !sysVerifyCode.equalsIgnoreCase(verifyCode)) { addActionError("验证码错误"); return "login"; } return "success"; } @Action(value = "logout", results = { @Result(location = "/pages/login.jsp") }) public String logout() { Map session = getSession(); if (session != null) session.clear(); return "success"; }} JSP<form action="login/login.action"></form><a href="login/logout.action">登出</a>其中Result注解中name属性为空,表示默认为"success"常用注解如下Namespace:指定命名空间ParentPackage:指定父包Result:提供了Action结果的映射(一个结果的映射)Results:Result注解列表ResultPath:指定结果页面的基路径Action:指定Action的访问URLActions:Action注解列表ExceptionMapping:指定异常映射(映射一个声明异常)ExceptionMappings:一级声明异常的数组InterceptorRef:拦截器引用InterceptorRefs:拦截器引用组