@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 關注
- 456 瀏覽
添加回答
舉報
0/150
提交
取消
