Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

jsp and servlets with jdbc

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some tutorials I am working through from the Sum core servlets and javaserver pages book. I have a question about using JDBC with JSP. All the examples in the book show you how to make a connection to a database using serlvets and display the information back to the browser using the println method. However, is there a way to return the result to a jsp page? What i'm trying to do is build an application that uses MVC. Have my servlet make the connection then have the result set passed back to the jsp page. How can I do this?
 
Sheriff
Posts: 67595
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
After your servlet collects the info it needs from the database, it can tack it onto the request as an attribute and forward to a JSP page. The JSP page retrieves the data to display from the request.
Be sure to forward rather than redirect since a forward maintains the same request context.
hth,
bear
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are really using MVC then the database access should be encapsulated in the 'Model' tier rather than in the 'Control' tier that is implemented by the servlet. The control servlet should invoke methods on the model tier and load the information onto the current request as specified by Bear so that the JSP/View tier can handle the display of the data.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic