This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes RequestDispatcher vs. out.println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher vs. out.println" Watch "RequestDispatcher vs. out.println" New topic

RequestDispatcher vs. out.println

Steve Tharp

Joined: Mar 19, 2001
Posts: 10
Can anyone tell me their experience on which will offer a better combination of performance and ease of maintenance:
RequestDispatcher forward() to shoot parameters to a .jsp using <% request.getAttribute() %> or having the servlet write out all the HTML with out.println?
Tony Alicea

Joined: Jan 30, 2000
Posts: 3222
"having the servlet write out all the HTML with out.println"
That could be a maintenance nightmare depending on the circumstances. Servlets really should not print HTML to the client. That's what JSPs are for

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Steve Tharp

Joined: Mar 19, 2001
Posts: 10
I totally agree that servlets should not write out the HTML. I am just trying to decide the best way to code our application. I started out using out.println but quickly realized the nightmare of maintaining it. So I am currently using the RequestDispatcher forward() method to populate data in a jsp. I am interested in knowing if anyone has experience with this design and if it hurt performance in any way.
jQuery in Action, 3rd edition
subject: RequestDispatcher vs. out.println
It's not a secret anymore!