求问,@Action(value="/login"在java语句中是什么意思?

@Action(value="/login"在java语句中是什么意思


森栏
浏览 410回答 2
2回答

慕村225694

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

手掌心

@为java中的注解。使用@Component("loginAction")在服务器容器中生成对应的组件bean。默认的@Component设置的Scope为singleton,即整个容器中只会生成一个这个bean,所有与状态相关的Bean需要声明为prototype。而Struts2的Action Bean正好都是有状态的,显然应该声明为prototype。
打开App,查看更多内容
随时随地看视频慕课网APP