码迷,mamicode.com
首页 > Web开发 > 详细

Struts2 Post json

时间:2015-04-03 22:31:39      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

$(function () {
  $('#saveMenu').on('click', function () {
    var data = {
      button: dataCondense(menuList.toJSON())
    }
    $.ajax({
      method: 'POST',
      url: '/weixin/saveMenu',
      contentType:'text/html',
      data: JSON.stringify(data),
      success: function (data) {
        // todo
      }
    })
    console.log(JSON.stringify(data))
  })
})


若要传送json到struts必须使用JSON.stringify(),否则在struts2中获取的是键值对,如下获取键值对

Enumeration<String> enumeration = request.getParameterNames();
		while(enumeration.hasMoreElements()){
			String key = enumeration.nextElement();
			System.out.println(key+"======"+request.getParameter(key));
		}

获取原始数据

HttpServletRequest request = ServletActionContext.getRequest();
		request.setCharacterEncoding("UTF-8");
		BufferedReader br = new BufferedReader(new InputStreamReader(
				request.getInputStream()));
		StringBuffer sb = new StringBuffer();
		String str = null;
		while ((str = br.readLine()) != null) {
			sb.append(str);
		}


Struts2 Post json

标签:

原文地址:http://blog.csdn.net/hackcoder/article/details/44860791

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!