• 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

JSP & JDBC implementation question

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
Currently I'm using JSP scriptlets to establish connectivity with a database (with all variables declared within a JSP page). This database will be accessed from a number of pages. I'm thinking about using a bean (with application scope) to establish a connection and store all necessary variables. This way, I can use the bean (and the database connection) by simply accessing the Connection variable. First, is there a fault in my logic here (I'm new to JSP)? Second, which would be a better implementation (in regards to security/efficiency):
1.) a bean as described above
2.) a JSP page with all necessary variables and database functions (sort of like a header file)
You guys are great. Thanks for any help/suggestions you can offer.
WS
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JSP page would be the worst possible choice for something like this. You should strive to keep your JSPs as purely display oriented as possible, and factor out processing -- such as database access -- into other Java elements.
Of the two choices you gave, the bean approach is vastly superior. However, you could do even better and abstract your data layer completely from the UI.
I'd suggest that you search these forums for the terms "MVC" and "model 2". A lot of good information on structuring web applications is to be had.
hth,
bear
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic