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

jsp and servlets with jdbc

 
mark babcock
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic