aspose file tools*
The moose likes JSP and the fly likes Print statement in JSP page after redirection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Print statement in JSP page after redirection" Watch "Print statement in JSP page after redirection" New topic

Print statement in JSP page after redirection

Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 79
I have written a JSP page and in that i am redirecting it to another page. Now after redirection i am printing a statement on the console. It is getting printed whereas when i am printing the same on the browser i am not able to print that. Please can any one tell me the difference between printing the same on the console and browser.

My first JSP page(one.jsp)
out.println("After redirect");
System.out.println("After out");

My second JSP(two.jsp)
out.println("In two.jsp");

Thanks in advance
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61043

That's exactly as expected.

All the redirect does is to set response headers. It doesn't cause any sort of magic that causes a change in normal Java execution behavior. So you see the console output.

But because the response header speicifes a redirect, you won't see any generated body. That's the way HTTP works.

In fact, you are lucky that writing to the response after the redirect doesn't cause an illegal state exception.
[ October 03, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jQuery in Action, 2nd edition
subject: Print statement in JSP page after redirection