Results 1 to 4 of 4
  1. #1
    anand12356 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default how to display data in a table format using jstl tag

    hello friends,
    i am having a problem in displaying the data in a table format using jstl forEach tag. i am using springs and retrieving data from a controller using model and view and storing it in an ArrayList. now i want to display it to the user using a jsp page. Please help.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Java Code:
    <table>
            <c:forEach var="script" items="${scripts}" varStatus="varCounter">
                <tr>
                    <td>${script.name}</td>
                    <td>${script.type}</td>
                </tr>
            </c:forEach>
            </table>
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    anand12356 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    LoginFormController.java

    public class LoginFormController extends SimpleFormController {

    @Override
    protected ModelAndView onSubmit(Object command) throws ServletException {

    Statement stmt;
    Connection connection;
    ArrayList processName=new ArrayList();
    ArrayList description=new ArrayList();
    ArrayList parentId=new ArrayList();
    ArrayList processType=new ArrayList();

    try {

    Class.forName("com.mysql.jdbc.Driver");
    connection=DriverManager.getConnection("jdbc:mysql ://localhost:3306/emsdb","root","mysql");
    stmt=connection.createStatement();
    String data="select * from processt";
    ResultSet resultSet=stmt.executeQuery(data);
    while(resultSet.next()){
    String row1=resultSet.getString("ProcessName");
    processName.add(row1);
    String row2=resultSet.getString("Description");
    description.add(row2);
    String row3=resultSet.getString("ParentId");
    parentId.add(row3);
    String row4=resultSet.getString("ProcessType");
    processType.add(row4);
    }

    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }



    ModelAndView modelAndView = new ModelAndView(getSuccessView());

    modelAndView.addObject("name", processName);
    modelAndView.addObject("description", description);
    modelAndView.addObject("parentId", parentId);
    modelAndView.addObject("processType", processType);

    return modelAndView;

    }





    thanks for the reply petr
    this is my controller class and i have created a view for it to show the values in table format....please modify this code.

    success.jsp

    <%@page import="java.util.ArrayList"%>
    <%@ page session="false"%>
    <%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="spring" uri="/spring" %>
    <html>
    <head>
    <title>Success</title>
    </head>
    <body>

    <table BORDER="1">
    <tr>
    <th>Name</th>
    <th>Description</th>
    <th>parent-Id</th>
    <th>Process-Type</th>
    </tr>

    <core:forEach begin="1" end="5">
    <tr>
    <td><core:out value="${name}"/></td>
    <td><core:out value="${description}"/></td>
    <td><core:out value="${parentId}"/></td>
    <td><core:out value="${processType}"/></td>
    </tr>
    </core:forEach>
    </table>



    <center>
    <a href="login.html">Back</a>
    </center>
    </body>
    </html>

  4. #4
    anand12356 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    do i need to create a pojo class for the controller to retrieve the data.
    Please reply i m stuckkk.... :mad::eek::(

Similar Threads

  1. populate html table using jstl
    By niteangell21 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 01-16-2011, 09:10 PM
  2. Replies: 1
    Last Post: 05-31-2010, 09:46 AM
  3. populate an HTML table(jstl)
    By Rajib27 in forum New To Java
    Replies: 0
    Last Post: 03-15-2010, 10:54 AM
  4. Data formatting for the <display:table>
    By yuchuang in forum Web Frameworks
    Replies: 3
    Last Post: 12-14-2007, 11:52 AM
  5. Replies: 0
    Last Post: 11-06-2007, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •