wood burning stoves 2.0*
The moose likes Servlets and the fly likes including jsp in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "including jsp in servlet" Watch "including jsp in servlet" New topic
Author

including jsp in servlet

ajinder singh
Greenhorn

Joined: May 09, 2008
Posts: 1
Hi,

i am a beginner. i am using servlets and jsp to fetch the records from database. once a query is made to database (in servlets), the records are fetched. i want to show these records on jsp file. i want to store the resultset in a variable, then include the jsp page using "reqestDispatcher" and on that jsp page, make a loop and show the records.
i know that we can store the variable as request variable or session variable. but i dont want to store the variable in them. i just want to make a variable, and use it in jsp using a loop. is this possible?
kindly help.

thanks in advance,
Ajinder

[ May 18, 2008: Message edited by: ajinder singh ]
[ May 19, 2008: Message edited by: ajinder singh ]
Ashok Kumar Babu
Ranch Hand

Joined: Jul 25, 2006
Posts: 129
Hi,

i know that we can store the variable as request variable or session variable. but i dont want to store the variable in them. i just want to make a variable, and use it in jsp using a loop. is this possible?


Please elaborate your question.


Ashok<br /> <br />SCJP 91%<br />SCWCD 88%
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
You can store the result in a cache with a specific key (identifier) [using Java Collection] and in your JSP you can retrieve the result from the cache [using the same key used to store the result]. This approach is useful only if the result fetched can be reused across requests [or sessions].
[ May 19, 2008: Message edited by: karthi keyan ]

http://www.skillassert.com


Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It's better to:

1) Not store resultSets any longer than necessary.
Grab what you need from them and release them.

2) Forward to your JSP (rather than include it).
If you follow the advice in #1, you should be able to close all of your database objects before forwarding so there will be no need to do an include.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: including jsp in servlet