The moose likes Servlets and the fly likes Servlet Response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Response" Watch "Servlet Response" New topic

Servlet Response

Scott Stanlick

Joined: Aug 06, 2002
Posts: 11
I have a strange situation where writing to the response writer works but performing a requestDispatch.include(rq, rs) does not! What I want to write to the response is the result of a jsp that I am trying to include. Am I missing something basic here? Is include different from writing directly to the response writer?

Joy Mukherjee
Ranch Hand

Joined: Aug 10, 2008
Posts: 62
How are you trying to get the dispatcher using ServletContext or ServletRequest ?

B.Tech (E.E),IIT Kharagpur<br />SCJP 5.0<br />SCWCD 5.0<br />PMP
Scott Stanlick

Joined: Aug 06, 2002
Posts: 11

RequestDispatcher dispatcher = request.getRequestDispatcher(getLocation());
dispatcher.include(request, response);

Shouldn't the output of the "included" JSP be the same as writing directly to the response?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

What is happening?

[Asking smart questions] [About Bear] [Books by Bear]
Scott Stanlick

Joined: Aug 06, 2002
Posts: 11
The response is being evaluated by a java script function and when I write to the response myself it works okay. If I include a JSP (that is the same content) it is as though there was no response at all! Is there a way to examine the response following the .include?
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Can you post more portion of your code so that we have understand better what the problem might be?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778


Please check your private messages for an important administrative matter.

Thanks, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Is there a way to examine the response following the .include?

If you mean examine what is actually sent to the client - sure. The Firefox browser has great plugins that will capture and show all the bits sent to a web page. I like the Firebug plugin.

You can seee exactly what Javascript is doing, etc etc.

Steve Luke

Joined: Jan 28, 2003
Posts: 4181

Can you show a full method that makes the .include call and misbehaves? And the JSP that is included as well?

If these are very large please make a mock up that behaves the same way but is a minimal example.

Can you also check your logs and see if an exception occurs during the process? Sometimes these errors get hidden when using JSPs and Servlets because part of the page has been committed before the error occurred.
[ August 17, 2008: Message edited by: Steve Luke ]

I agree. Here's the link:
subject: Servlet Response
It's not a secret anymore!