• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to return list of data from java class to .JSP file

 
Preethi sakar
Greenhorn
Posts: 19
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i'm using eclipse Kepler to create J2EE project.i created student class which return list of information. how to access list in JSP page??

Thanks in advance

Have a nice day

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get the list in the controller and pass it to the JSP as a request-scoped variable.

If you don't understand that, start with this article.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. It's JEE, not J2EE.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returning a list of objects to JSP page is similar to returning a single object to JSP.

Actually its not returning , its like setting attributes so that JSP page can get those attributes.

Here is how we set an attribute


So how we will retrieve this attribute set in request scope. We can do that using EL expressions in JSP page , you can do that with scriplets also in JSP page but that is not recommended.
This is how we retrieve the message attribute set in request scope by servlet, in JSP page.


Now coming to your question , how can you get a list of objects set by servlet in your JSP page.
Well its similar to above , and most probably if you want a list in JSP page You will like to iterate over that list.


And to access the habitList in JSP page , you can do that as before.



I think you are trying to iterate over list , to do that you can use jstl forEach tag. And to use JSTL you should have jstl1.2 jar file under WEB-INF/lib folder.
You can download jstl 1.2 jar from JSTL 1.2 jar.

One last thing you have to do is to inclde a taglib directive in your JSP page so that JSTL tags can be interreted in JSP page.

Now your JSP page will look something like this



And you will get below result




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!