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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Print statement in JSP page after redirection" Watch "Print statement in JSP page after redirection" New topic
Author

Print statement in JSP page after redirection

Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 79
Hi,
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)
<%
response.sendRedirect("two.jsp");
out.println("After redirect");
System.out.println("After out");
%>

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

Thanks in advance
regards
Prashanth
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

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: http://aspose.com/file-tools
 
subject: Print statement in JSP page after redirection