Retrive values from an arraylist and display in a jsp?



Share on Google+Share on Google+

Sarbu Diana
Retrive values from an arraylist and display in a jsp?
2 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners


I need help in jsp to display values of an ArrayList in jsp.

There is a java file containing a method which is returning an ArrayList.

I want to display the records of the ArrayList in jsp in a tabular form/way.

if (request.getParameter("action") != null) { Open connection to the database; Read parameters from the JSP formular (parameters are NAME and YEAR of each student); stmt.executeUpdate("insert into Students(name,year) values('"+name+"', '"+year+"')"); Close the connection;

ArrayList<Student> students = StudentsManager.getInstance().getStudents();
    <body bgcolor=#4AA02C>
        <h2>Student list</h2>
        <table border="1" cellspacing="1" cellpadding="8" bgcolor= #EBDDE2> 
            <td bgcolor= #FF9966><b>ID</b></td>
            <td bgcolor= #FF9966><b>Name</b></td>
            <td bgcolor= #FF9966><b>Year</b></td>
            int no = 1;
            Student s = students.get(no); 
              <td><%= no %></td>
              <td><%= s.getName();%></td>
              <td><%= s.getYear();%></td>


(First RED X)<%}else{%>

   <jsp:forward page = "Student.jsp"/> // Student.jsp is the form where name and year of a student 
                                                       //    is requested to be entered to the database
(2nd RED X)  <%>}%>

1st red X: syntax error on token â?želseâ??, finally expected.

2nd red X: Multiple annotations found at this line: -syntax error on token â?žcatchâ??, Identifier expected - syntax error on token â?ž}â??, delete this token - syntax error on token â?ž>â??, delete this token

View Answers

June 24, 2012 at 4:09 AM

I noticed the problem now. hehe...forget

June 25, 2012 at 12:57 PM

Anyways, here is a link. It might be helpful for you.


Related Tutorials/Questions & Answers: