@Action(value="/login"在java语句中是什么意思
2 回答
慕村225694
TA贡献1880条经验 获得超4个赞
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的访问URL
Actions:Action注解列表
ExceptionMapping:指定异常映射(映射一个声明异常)
ExceptionMappings:一级声明异常的数组
InterceptorRef:拦截器引用
InterceptorRefs:拦截器引用组
手掌心
TA贡献1942条经验 获得超3个赞
@为java中的注解。使用@Component("loginAction")在服务器容器中生成对应的组件bean。默认的@Component设置的Scope为singleton,即整个容器中只会生成一个这个bean,所有与状态相关的Bean需要声明为prototype。而Struts2的Action Bean正好都是有状态的,显然应该声明为prototype。
- 2 回答
- 0 关注
- 469 浏览
添加回答
举报
0/150
提交
取消
