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?
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
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.
Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams