Struts2-学习笔记系列(15)-ajax支持和JSON

7.1stream类型的result

使用stream就无需jsp页面,直接在action想浏览者生成指定的响应

 1  
 2 
 3 @Override
 4 public java.lang.String execute() throws Exception {
 5     stream = name.equals("zcx") ? new ByteArrayInputStream("登录成功".getBytes("UTF-8"))
 6             : new ByteArrayInputStream("登录失败".getBytes("UTF-8"));
 7     return SUCCESS;
 8 }
 9 
10  

 

7.2json

引入struts-json-plugin.jar文件,在action result配置 type=’json’   contenttype=’text/html’

即可返回json的result。在序列化过程中,使用@JSON修改json对象中属性名称

 

Struts2和ASP.NET MVC神似,但是,明明是controller,却要取个action的名字。搞不懂。

 

Spring MVC已经基本可以替代Struts了。那么重点是:Spring MVC系列即将上线,欢迎浏览!!!!

希望在园子里,能交到极客朋友

 

posted @ 2016-06-04 22:39  逆风飞行  阅读(220)  评论(0编辑  收藏  举报