Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets with JDBC

 
Raghu Kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
i have a small doubt regarding JDBC with servlets.
suppose assume that i have 3 html's( called using servlets). main page which takes care of logging in, second page is to retrieve and display data from database and third page is to enter data. So if i create a connection object,statement object if the user is valid in the first page can i use the same objects in the second and third html pages(servlets)? If so what should i do? Do i need to declare these objects to be static or is there any other way to handle this? Hope my question is clear?
Cheer's,
Raghu
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sort of problem is precisely why the concept of "sessions" was invented. Look up HttpSession in your servlet books/websites, and you should find lots of examples of gathering or chacking information in one servlet and using it in another.
Even if your pages are generated by a single servlet (not usually a good idea, unless you delegate to other classes or templates), you should still store your information in the session to make sure that your system still works when more than one person tries to access it at once.
 
Raghu Kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Frank. I am not using the same servlet for all the three pages. i am using three servlets for each three html pages. so i mean to say that in this case can i access the object's of one servlet in another servlet?
Originally posted by Frank Carver:
This sort of problem is precisely why the concept of "sessions" was invented. Look up HttpSession in your servlet books/websites, and you should find lots of examples of gathering or chacking information in one servlet and using it in another.
Even if your pages are generated by a single servlet (not usually a good idea, unless you delegate to other classes or templates), you should still store your information in the session to make sure that your system still works when more than one person tries to access it at once.

 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. You may put any objects into the session. It's like a Map, and once a session is created you may put objects in and retrieve them by name from any cooperating servlet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic