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
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.
subject: RequestDispatcher vs. out.println
Similar Threads
How to navigate from jsp-to servlets-and again to another -jsp
tomcat return an error +mvc
RequestDispatcher doubts