• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to retrieve the bean-objects of an arraylist in jsp

 
bandaru Babu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page import="java.util.*" %>
<HTML>
<HEAD>
<TITLE>STUDENTS DETAILS</TITLE>
</HEAD>
<BODY BGCOLOR="66FFFF">
<CENTER>
<FONT SIZE="4" FACE="Verdana" COLOR="DodgerBlue">
MASTER OF COMPUTER APPLICATIONS <P>FINAL YEAR STUDENTS <P>

<% Object a2[]=((ArrayList)request.getAttribute("a1")).toArray(); %>
<TABLE BORDER="1" BGCOLOR="LightSalmon">
<% for (int i=0;i<a2.length;i++) { %>
<tr><td><% out.print((CourseStudents)(a2[i]).getStuname()); %>
</td><td><% out.print((CourseStudents)(a2[i]).getStuno()); %></td></tr>
<% } %>
</table>
</CENTER>
</BODY>
</HTML>


hi everybody
in my program CourseStudents is name of bean. in my servlet program i added these bean objects into an arraylist and send it to
this jsp. please help me how to retrieve the objects of a bean from arraylist and how to show the results in jsp.

hanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, scriptlets are discredited. You should be using the JSTL and EL in your pages.

Secondly, you never explained what problems you are having with the existing code.

Finally, your code is rather a mess. You use different casing for the HTML throughout, which (in addition to not using code tags for display) makes your code hard to read. Making your code easy to read is a first step in getting quality help.
 
Vijitha Kumara
Bartender
Posts: 3953
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi bandaru,
Please use code tags when posting code here. And look for JSP standard actions, EL (Expression Language) expressions and JSTL. Those when used together all your java code (scriptlets, scriptlet expressions, scriptlet declarations) in the JSP can be eliminated.
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use EL for this, have a look at this: http://java.sun.com/products/jsp/reference/techart/unifiedEL.html (2005 article but I think it's useful)
Look carefully to the JSTL <c:forEach tag you will see that does exactly what you need in that JSP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!