永寂如孤星 2019-06-24 19:54 采纳率: 0%
浏览 1016

如何通过EL表达式拿去List<Object>数组中的不同List中所包含的值?

protected void selectArtclesByVagueType(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        int VagueTypeId = 1;

        if(request.getParameter("VagueTypeId") != null){
            VagueTypeId = Integer.parseInt(request.getParameter("VagueTypeId"));
        }

        List<Artcle> ArtcleList = artcleBIZImp.selectArtclesByVagueType(VagueTypeId);   


        List<User> userList = new ArrayList<User>();

        for(int i = 0;i<ArtcleList.size();i++){
            try {
                User user = userBIZImp.selectUserByUserId(ArtcleList.get(i).getUser().getUserId());
                userList.add(user);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        List<Object> list = new ArrayList<Object>();
        list.add(ArtcleList);
        list.add(userList);

        request.setAttribute("list",list);

        request.getRequestDispatcher("index.jsp").forward(request, response);
    }

如果直接使用
${list.ArtcleList.值}
${list.userList.值}
的方式取值会报错,报错信息如下

严重: Servlet.service() for servlet ArtcleActionServlet threw exception
java.lang.NumberFormatException: For input string: "ArtcleList"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:447)
    at java.lang.Integer.parseInt(Integer.java:497)
    at javax.el.ListELResolver.coerce(ListELResolver.java:166)
    at javax.el.ListELResolver.getValue(ListELResolver.java:51)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:182)
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:919)
    at org.apache.jsp.index_jsp._jspx_meth_c_005fforEach_005f0(index_jsp.java:1218)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:760)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at com.takun.action.ArtcleActionServlet.selectArtclesByVagueType(ArtcleActionServlet.java:65)
    at com.takun.action.ArtcleActionServlet.service(ArtcleActionServlet.java:31)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)


  • 写回答

3条回答 默认 最新

  • 小周瑜 2019-06-24 21:01
    关注
    <c:forEach  items="${list}"  var="item">  
    </c:forEach>  
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀