File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Proper mix of Servlets and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Proper mix of Servlets and JSP" Watch "Proper mix of Servlets and JSP" New topic

Proper mix of Servlets and JSP

Kenny Dilger

Joined: Jan 14, 2002
Posts: 11
Is there a "proper" way to mix Servlet and JSP pages together? The book I have "More Servlets and JavaServer Pages" says that JSP pages should mostly be concerned with formatting of data received by a servlet.
So does this mean that the Servlet should take care of Data collecting (be it either a Database or some other source) and the JSP page should just take that data and display it.
In my current project I am downloading email message information from an email server and storing the messages in a Vector. Then the JSP page just uses the data from the Vector instead of making its own connections.
In the future I would also use the method for database information. One problem I see could be if the data you are collecting is really large, say from a large database table.
Thanks for any info,
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
This is a good way to use JSP, and helps encourage a separation between the data model and the presentation.
As for your worry about loading large database result sets. You are right to worry, but the solution is not some kludge to connect to the database direct from the JSP, but instead to spend a little time thinking about why you have large amounts of results, and how to reduce them.
Web application users need precise, targetted information, and rarely have any use for mile-long screens full of stuff (imagine if this bulletin board were just one huge list of thousands and thousands of posts ). A query which returns so many results is usually due to a mistake or an inflexible query system. Study the users' needs more, find out how they would refine the query, and offer them that option.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
David Peterson
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
Good response.
I agree. Here's the link:
subject: Proper mix of Servlets and JSP
It's not a secret anymore!