File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Android Security Essentials Live Lessons this week in the Android 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: 60785

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]
I agree. Here's the link:
subject: Print statement in JSP page after redirection
Similar Threads
strange output !! include / jsp:include
JSP forward tag
What is the difference between Submit and Foward in jsp
jsp:getProperty calling bean from specific scope
Calling one JSP from another JSP