acpig95 2019-08-13 15:13 采纳率: 0%
浏览 522
已采纳

关于JSONObject类型返回值在jsp页面循环遍历问题??

java后端

    // 查询培训类型,前端使用select选择。
   Result resultType = Invoker.invoke("J_THP_002_0102", null, page);
   JSONObject bodyType = (JSONObject) resultType.getBody();
   System.out.println(bodyType);
   // 将培训类型放入servletContext域中,用于跨页面获取。
   ServletContext application = request.getSession() .getServletContext();
   application.setAttribute("noticeType",bodyType.get("type"));

获取的数据格式为:

{"returnCode":"200","returnMsg":"查询成功","type":[{"ttType":"技术类","ttId":"a6a9fda2ef2e4013a9b29d45209c4bb5"},{"ttType":"管理类","ttId":"cdffa8fb52fc447eb3b473bf1bbef60c"},{"ttType":"其他","ttId":"214dc36b904e4893b2719e53bcddc36d"}}]

前端jsp页面

<div class="layui-form-item">
                <label class="layui-form-label">培训类型</label>
                <div class="layui-input-block">
                 <select id="ttId" name="ttId" required lay-verify="required>
                  <option value="">请选择类型</option>
                  <c:if test="${application.getAttribute('noticeType')!=null}">
                   <c:forEach var="type" items="${application.getAttribute('noticeType')} ">
                    <option value="${type.ttId) }">${type.getttType}</option>
                   </c:forEach>
                  </c:if>
                 </select>
                </div>
            </div>

请问数据格式怎么处理可以在jsp页面获取值???
谢谢

  • 写回答

2条回答 默认 最新

  • qiangchen1990 2019-08-13 16:17
    关注

    application.getAttribue("noticeType")获取到的是jsonobject对象,不是数组,需要在获取一次层。
    application.getAttribue("noticeType").get("type")才是数组,c:foreach才可以进行迭代

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog