This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Servlets and the fly likes dispatching correctly to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "dispatching correctly to jsp" Watch "dispatching correctly to jsp" New topic

dispatching correctly to jsp

Michael Changarovi

Joined: Jan 25, 2005
Posts: 8
Hello forum,

I am facing a problem when dispatching from a servlet to a jsp page. Instead of seeing the page's response, its code is printed on the browser's window. My code is

RequestDispatcher dispatch = getServletContext().getRequestDispatcher(pageName);
dispatch.include(request, response);

and it causes no errors.

Any suggestions would be more than welcome!

Thank you

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17275

Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it


Thanks! and welcome to the JavaRanch!


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Mala Sharma
Ranch Hand

Joined: Oct 29, 2004
Posts: 76
Hello Micheal,

I'm a begineer at servlets as well but i'll take a stab at it. I think you're problem lies here:

You're not forwarding it. Try this instead:

Let me know how it worked out.

Michael Changarovi

Joined: Jan 25, 2005
Posts: 8
Thanks for the reply. I wouldn't want to alter the code I am using - it is sort of a black box. It has been working fine till now and there must be a reason for including and not forwarding. I just changed the target pages from html to jsp in order to get richer output. The problem is that the code of the jsp page is displayed instead of its response. This is not the case for html pages. This is the default behaviour of the browser if I drag and drop a jsp page on it.

sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Which servlet container you are using.


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
Michael Changarovi

Joined: Jan 25, 2005
Posts: 8
The application is deployed in Oracle AS 10g.
Any suggestions?

Harsha DN

Joined: Jan 25, 2005
Posts: 1
Hi Micheal,
This is my first post to the forum. Hope it helps!!
The reason why I think this is happening is because there might be something wrong in your .jsp file which was previously a .html file. May be a mismatch in tags or something which is resulting in your jsp code being displayed.
Please double check your jsp code and let me know if this helps.

K Nally

Joined: Sep 30, 2003
Posts: 13
Try using the Request object instead of the ServletContext:

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

This worked for me.
Michael Changarovi

Joined: Jan 25, 2005
Posts: 8
I found out that when I erase the jstl code from the jsp page it is dispatched just fine, just as you claim... But when I try to use jstl the pages apears again as text

Michael Changarovi

Joined: Jan 25, 2005
Posts: 8
I finally solved my problem..
It had nothing to do with the dispatching of the page after all.
I am using jstl in the page and the jstl code is broken in several parts so that I am using imports to concatenate them in a single page. It seems though that the <fmt:bundle> and </fmt:bundle> tags myst always be in the same page - so I cannot dispatch to the page and I presume that the dispatch method is incorrect. This is not the only case of problematic jstl code partitioning I came across. Anyway, the whole thing is a real mess because the code is not pure jstl, it is mingled with jsp..
I'll just keep on rocking..

Thanks for the replies everyone!!!

I agree. Here's the link:
subject: dispatching correctly to jsp
It's not a secret anymore!