Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

including jsp in servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic