Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing info from servlet to jsp

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm learning
i have a servlet that deals with database and gets a recordSet; i've an util class that prepares data from that recordset to be presented and now i want to pass this string (all the prepared data from util class) that i have in my servlet to a jsp (presentation); the examples i saw used something along this:

my question is: is the standard way to use httpsession to tranfer data from servlet to jsp? or instead tranfer the util class directly and have the jsp deal with it? or any other way?

TiA
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by miguel lisboa:
my question is: is the standard way to use httpsession to tranfer data from servlet to jsp?


No, the request scope is much more commonly used. The session would only be used for data that needs to persist over the course of the session rather than merely from the servlet to the JSP for this request.

or instead tranfer the util class directly and have the jsp deal with it?


I have no idea what you mean by this.
[ November 18, 2006: Message edited by: Bear Bibeault ]
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea what you mean by this.

i refer to this post from Stan James (here)
request.setAttribute("name", someObjectTheJSPNeedsToUse);getServletContext().getRequestDispatcher(jspName).forward(request, response);

The session would only be used for data that needs to persist over the course of the session rather than merely from the servlet to the JSP for this request.
i'm sorry but i dont quite get what you mean: are you saying that, for example, for dysplaying the contents for a very simple blog page my solution would be ok?
[ November 18, 2006: Message edited by: miguel lisboa ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan's example correctly uses request scope to "pass" the data from servlet to JSP.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic