• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dispatching correctly to jsp

 
Michael Changarovi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Michael
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Micheal"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
Mala Sharma
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mala
 
Michael Changarovi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Michael
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Which servlet container you are using.

Regards,
Sawan
 
Michael Changarovi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application is deployed in Oracle AS 10g.
Any suggestions?

Michalis
 
Harsha DN
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Harsha
 
K Nally
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the Request object instead of the ServletContext:

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

This worked for me.
 
Michael Changarovi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Changarovi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!

Michael
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic