2 maidanglao12 maidanglao12 于 2016.02.03 10:12 提问

Struts1中map转换成json传到前台时取不到值——求指点! 3C

后台报这个:

  • Property 'servlet' has no read method. SKIPPED
  • Property 'servletFor' has no read method. SKIPPED
  • Property 'servlet' has no read method. SKIPPED
  • Property 'servletFor' has no read method. SKIPPED
  • Property 'servlet' has no read method. SKIPPED
  • Property 'servletFor' has no read method. SKIPPED
  • Property 'servlet' has no read method. SKIPPED
  • Property 'servletFor' has no read method. SKIPPED
  • Property 'servlet' has no read method. SKIPPED
  • Property 'servletFor' has no read method. SKIPPED
  • Property 'servlet' has no read method. SKIPPED
  • Property 'servletFor' has no read method. SKIPPED
  • Property 'servlet' has no read method. SKIPPED
  • Property 'servletFor' has no read method. SKIPPED

Java代码 :

HttpSession session=request.getSession();
    String logincode= "";
    if(this.exportProvider==null){
        this.exportProvider=new ExportProviderImpl();
    }

    if (request.getSession().getAttribute("loginCode")!=null) {
        logincode=request.getSession().getAttribute("loginCode").toString();
    }
    try {

         response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode("财务批量数据", "UTF-8") + ".xls");
         response.setContentType("application/vnd.ms-excel"); 
         HashMap maps=new HashMap();
         if (!"86".equals(logincode)) {
             maps.put("logincode", logincode);
        }
        Map m=this.exportProvider.getJigouYear();
        List l1=(List)m.get("年");
        List l2=(List)m.get("机构");
        JSONObject jo=JSONObject.fromObject(m);
        response.getWriter().print(jo); 
        response.getWriter().flush();
        response.getWriter().close();
    } catch (Exception e) {

        e.printStackTrace();
    }
    return null;

前台 :

$.ajax({

type: "POST",

url: "../main/exportexclelist2.action",

//json格式接收数据

dataType: "json",

success: function (data) {

alert(data[i]);
}

});

}

Struts配置:


3个回答

zcxgz362324
zcxgz362324   2016.02.03 17:45

response.setContentType("application/vnd.ms-excel"); 这句代码没问题? 你试一下改为"text/html" 对了的话就给分哦

maidanglao12
maidanglao12   2016.02.03 10:18


zhangjs712
zhangjs712   2016.03.26 17:57

我看你是想实现文件的下载功能,如果下载文件的话,返回JSONObject 肯定是不能获取的。
ajax函数的返回类型只有xml、text、json、html等类型,没有“流”类型,

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!