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

Once executed and accessing multiple times?

 
bala chidambaram
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Hans Bergsten
Author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic