Struts2采用注解方式配置url和Action的映射

5 篇文章 0 订阅
2 篇文章 0 订阅
=================注解方式action的格式=================
?
1
2
3
4
5
@Result (name= "ajaxData" ,params= { "root" , "jsdata" },type= "json" )
@Result (name= "result" ,params= { "root" , "result" },type= "json" )
@Result (name= "indexView" ,location= "/metadata/indexView.jsp" ,type= "dispatcher" )
@Result (name= "jsonData" ,params= { "root" , "jsdata_index" },type= "json" )
@Result (name= "excel" ,params= { "contentType" , "application/vnd.ms-excel" , "inputName" , "excelStream" , "bufferSize" , "1024" , "contentDisposition" , "filename=export.xls" },type= "stream" )
@Result相当于struts.xml文件中的<result>元素的内容。使用@Result必须指定一个name属性,相当于<result name=””/>另外,它还有几个可选的属性。  
☆ type 相当于<result type=””/>指定返回视图资源的类型  
☆ location 相当于<result>…..</result>中间部分,用于指定实际视图位置  

☆ params:该属性相当于<result/>元素里多个<param../>子元素的作用,用于为该Result指定参数值。该属性应满足{“name1”,”value1”,”name2”,”value2”}格式

=================注解方式action实现跳转=================

@Result实现页面跳转  成功跳转到一个jsp ,不成功跳转到另一个jsp
?
1
2
3
4
5
@ParentPackage (value= "struts-default" )
@Action (value= "studentAdd" ,results={
     @Result (name= "success" ,location= "/usersuc.jsp" ),
     @Result (name= "error" ,location= "/usererror.jsp" )
})
@Result实现跳转到另一个action
?
1
2
3
4
5
@ParentPackage (value= "struts-default" )
@Action (value= "studentAdd" ,results={
     @Result (name= "success" ,type= "chain" ,location= "studentList" ),
     @Result (name= "error" ,location= "/usererror.jsp" )
})
chain 用于把相关的几个action连接起来,共同完成一个功能。处于chain中的action属于同一个http请求,共享一个ActionContext  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值