aspose file tools*
The moose likes JSP and the fly likes Once executed and accessing multiple times? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Once executed and accessing multiple times?" Watch "Once executed and accessing multiple times?" New topic
Author

Once executed and accessing multiple times?

bala chidambaram
Greenhorn

Joined: Jan 19, 2004
Posts: 24
hi,
On refering the post '1 mar onclick()', i found that we access server's output more than once after it's first execution. am i right?
If so, would anyone tell me how to do that?
Thank u.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Since the data is generated on the server side, if you wish to avoid accessing the same set of data from DB many times, you can put your ResultSet inside the session.

Then, you can access to the same set of the data many times, without re-querying the DB.
Does this solve your problem?
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Putting ANY database objects in your session is a VERY bad IDEA indeed.
It will in an environment with even a moderate load very quickly lead to database resource depletion which in turn can cause your entire database server (and as a result your web application) to hang waiting for connections to be freed!
Rather capture the ResultSet data into custom objects which you store in a List of some sorts and work on that.
This is no theoretical problem btw, I've experienced it myself (luckily it wasn't my code or application, though it was affected as it used the same database).


42
Hans Bergsten
Author
Ranch Hand

Joined: Dec 01, 2003
Posts: 106
Originally posted by Jeroen Wenting:
Putting ANY database objects in your session is a VERY bad IDEA indeed.
It will in an environment with even a moderate load very quickly lead to database resource depletion which in turn can cause your entire database server (and as a result your web application) to hang waiting for connections to be freed!
Rather capture the ResultSet data into custom objects which you store in a List of some sorts and work on that.
This is no theoretical problem btw, I've experienced it myself (luckily it wasn't my code or application, though it was affected as it used the same database).

I definitely agree with this advice. One convenient class for capturing and caching the ResultSet data (if you alread use JSTL) is the JSTL javax.servlet.jsp.jstl.sql.Result class. An instance of this class that captures the content of a ResultSet can be created by the toResult() methods on the javax.servlet.jsp.jstl.sql.ResultSupport class. The Result class provides convenient ways to access the cached data either from a servlet or using the EL and the <c:forEach> actions in a JSP page.
I discuss this in more detail in Chapter 24 of the 3rd edition of my JavaServer Pages book (O'Reilly).


Hans Bergsten, hans@gefionsoftware.com<br />Author of O'Reilly's<br />- JavaServer Pages,<br />- JavaServer Faces<br /><a href="http://www.hansbergsten.com/" target="_blank" rel="nofollow">http://www.hansbergsten.com/</a>
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Hans,
Thanks for pointing out a feature of JSTL. In the past, when JSTL does not exist, and we are too *lazy* to convert ResultSet into other format of data, we simply try to do the most *convenient* way.
In addition, I would like to know, beside the Result listing, what other JSTL features are new for data presentation?
Seems to me that, JSTL is a similar idea of XSL, while JSTL works with Java Objects and XSL works with XML objects.
Nick.
Hans Bergsten
Author
Ranch Hand

Joined: Dec 01, 2003
Posts: 106
Originally posted by Nicholas Cheung:
Hi Hans,
Thanks for pointing out a feature of JSTL. In the past, when JSTL does not exist, and we are too *lazy* to convert ResultSet into other format of data, we simply try to do the most *convenient* way.
In addition, I would like to know, beside the Result listing, what other JSTL features are new for data presentation?
Seems to me that, JSTL is a similar idea of XSL, while JSTL works with Java Objects and XSL works with XML objects.
Nick.

JSTL is a set of "standardized custom tag libraries" (i.e., implemented and used as regular custom tag libraries but defined by a specification), covering areas such as conditional processing and looping, i18n, database access and XML processing. Only the XML processing library overlaps with XSLT, offering an easier (IMO) way of merging data from XML sources and other data sources (e.g., databases).
For an overview of JSTL, you may want to read my articles about JSTL available on http://onjava.com. Search for "Hans Bergsten" to find them, along with other articles I've written about JSP and JSTL.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Hans Bergsten:
For an overview of JSTL, you may want to read my articles about JSTL available on http://onjava.com. Search for "Hans Bergsten" to find them, along with other articles I've written about JSP and JSTL.

But, Mr.Bergsten, I just sought using your name in the search textfield and here is the result of the search... but I can't find any articles related to JSTL 1.1... There are only JSTL 1.0... :roll: Is it because JSTL 1.0 is not that different from JSTL 1.1 and there is no new articles about JSTL 1.1?
Anyway, other articles are excellent... I did use JSP 2.0: The New Deal both part 1 and part 2 for the SCWCD 1.4 Beta Exam... They are really cool, especially in EL stuff...
Thanks a lot...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Ko Ko,
I also read those articles and the sample chapter while I am preparing SCWCD beta.
I think the core technologies maybe the same, but JSTL 1.1 adds more functions and become more flexiable than JSTL 1.0.
Nick.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Once executed and accessing multiple times?