=================注解方式action的格式=================
@Result相当于struts.xml文件中的<result>元素的内容。使用@Result必须指定一个name属性,相当于<result name=””/>另外,它还有几个可选的属性。
☆ type 相当于<result type=””/>指定返回视图资源的类型
☆ location 相当于<result>…..</result>中间部分,用于指定实际视图位置
@Result实现跳转到另一个action
chain 用于把相关的几个action连接起来,共同完成一个功能。处于chain中的action属于同一个http请求,共享一个ActionContext
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"
)
|
☆ 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"
)
})
|
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"
)
})
|