• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send the Resulset values to a JSP page from servlet?

 
praveen kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to send the Resulset values to a JSP page from servlet?

suppose, your query gets 10 rows data from table and stores in Resulset,
Then how to send this resultset valuses to JSP page to display these values.


praveen
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several approaches.
My favorite is to create a row bean with simple setters and getters for each column. For each row in the resultSet, create a new row bean and add it to an instance of List. The list can then be bound to request scope before forwarding to the JSP.
There are JSTL tags for iterating through such lists.
 
praveen kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to reply.

could you please give me some other solution...

I am a newbie guy...

praveen
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's important to grab the data that you need out of the ResultSet as soon as possible and give it back to the database. Some database drivers lock, timeout or reuse the Connection and you can get some very strange problems if you are not careful.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by praveen kumar:
could you please give me some other solution...

I am a newbie guy...


Actually, what Ben said is very simple and straight. And we used to explain like this to a newbie, like you. Otherwise, you have an option to read about TO/VO. Visit the URL given below. It will explain you TO/VO Pattern. It might be, relatively, easier for you to get this. It is simple or you can say simplest.

Transfer Object
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by praveen kumar:
How to send the Resulset values to a JSP page from servlet?

suppose, your query gets 10 rows data from table and stores in Resulset,
Then how to send this resultset valuses to JSP page to display these values.


praveen


make a java bean representing the row of the table whose 10 rows you would like to send to the jsp..now make any array of ten of type this newly created bean. set this in the session and forward this request to the jsp. which can take this array from the session and display the data in a tabular format.

cheers!
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:
make a java bean representing the row of the table whose 10 rows you would like to send to the jsp..now make any array of ten of type this newly created bean. set this in the session and forward this request to the jsp. which can take this array from the session and display the data in a tabular format.


Dont use session scope for this until and unless you really need it. Use request scope instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!