• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use Datasource in JSP??

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm new to struts.
I just don't know how to use Datasource in JSP.
In Actions, I can have datasource by using GetDatasource(...) method.
However, if I use traditional method: create InitialContext, the look up by naming service, I could not obtain the datasource object.
So there is the problem, the GetDatasource(...) method looks like from the Action class, how can I use it in JSP ?
Besides, for the MVC, if JSP is the view, is it OK to read data from the database by using a bean(the Model), or should I pass all requests to database to a Controller?

Thanks very much !!!
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep the calls out of your view and model.

Your Actions should contain the calls. Better yet, the Actions should call on another object to make the calls.
 
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah no database calls in your JSP. You should be able to load all the information you need in your following screen from your action handler, should actually look like

Action instantiates DAO object
call method on DAO object to return value object you need.
Set value object or whatever you need into request
Go to next JSP

Should not call datasource directly from action as stated above, look into the DAO Factory pattern to uncouple your web app from a particular datasource.....
 
Like Zhang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I see.
So I need to save what I need (for example, a result set) in session or cookie, and then read it out from the next JSP ?
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic