File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes To retrieve data from the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "To retrieve data from the database" Watch "To retrieve data from the database" New topic

To retrieve data from the database

S.R.K.Vivek Raju
Ranch Hand

Joined: Sep 23, 2004
Posts: 58
Hi all

I have a simple question, Can I retrieve data from the Mysql database on page load. i.e i am storing the information from page one and i want to retrieve that stored information on my page two. And this should be retrieved on page load.

Is this possible, if yes could anybody guide me with some tips.


With Regards
S.R.K.Vivek Raju.
todd runstein
Ranch Hand

Joined: Feb 15, 2005
Posts: 64
Are you talking about web pages? If so, retrieve the data as page one is being created and store the results in a session attribute. You can simply write the data to the page for page one. For page two, have it simply pull out the data from the session attribute and write the data to the page.

If you're talking about using the "onload" attribute of the html body tag, you'd need to do this through javascript and XmlHttpRequest object. I guess I'm having trouble determining whether you mean "on page load" literally or not.

Hope that helps
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

While JDBC is mentioned, this is really a question on how web pages work. Moving to Servlets.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

"page load" is not a servlet/JSP phrase either.

Are you talking about the the Javascript "onLoad" event?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
Well the question isn't clear, but I will take a stab at it anyway. The short answer is no matter which meaning you have it can be done.

If by 'page' you mean servlet/jsp and by 'load' you mean on 'request' then you can access get data in page 1 and access it in page 2. This can be done by putting the data into session, request, application, page, or static scope among others. In jsp these are all implicit variables.

If by 'page load' you mean when the servlet/jsp is first loaded it can also be done by coding the servlets 'jspInit' method or the servlets 'init' method. - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
I agree. Here's the link:
subject: To retrieve data from the database
It's not a secret anymore!