JSP- getting array data into jsp from java

前端 未结 3 400
栀梦
栀梦 2021-01-26 06:31

I have to display data fetched from DB to JSP. I am using spring MVC. I have stored data in List in java. Now i need to access this list in JSP and display it in tabular form.

相关标签:
3条回答
  • 2021-01-26 07:01

    You can add your data in session and access it in table.jsp.

    Once you get data on JSP you can easily render as you want using html + jsp combination.

    Hope this helps.

    0 讨论(0)
  • 2021-01-26 07:10
    List<List<?>> data = new ArrayList<List<?>>();
    int col = -1;
    List<?> row;
    while(rs.next())
    {
      if (col != rs.getInt(1))
      {
        col = rs.getInt(1);
        row = new ArrayList<?>();
        data.add(row);
      }
      row.add(rs.getObject(3));
    }
    getRequest().setAttribute(data);
    
    0 讨论(0)
  • 2021-01-26 07:18
    • Process it on servlet and store it in 2D array of String or List<List<String>>

    • Set it as attribute to request, forward request to jsp.

    • on jsp use JSTL to represent data. using <c:forEach>

    0 讨论(0)
提交回复
热议问题