File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes passing info from servlet to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing info from servlet to jsp" Watch "passing info from servlet to jsp" New topic
Author

passing info from servlet to jsp

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
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


java amateur
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
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

Joined: Jan 10, 2002
Posts: 60782
    
  65

Stan's example correctly uses request scope to "pass" the data from servlet to JSP.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
thanks a lot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing info from servlet to jsp
 
Similar Threads
Code for transfering data from JSP to Excel Sheet
ComboBox Item Display
Struts Problem
Struts Problem
Struts Problem