I have a jsp page which has post comment box. I have written a servlet which takes a comment from the text area for the comment box and writes the comment to the database and redirects all the comments stored in the database to the page for display(using request dispatcher). The new comment displays along with all the previous comments. I want to have a functionality where the previous comments are displayed on page load by connecting it to the database . How can I accomplish this.

if you already have a page that displays all the comments then the question is not "how" but "where" no?

simply reuse that code in the first page! :)
unless im not understanding right what you were saing in your question, but anyways.

In your page, simply have a section call the database functions to execute a SELECT statement on all comments, then loop through the comments and display them in your page!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.