Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print statement in JSP page after redirection

 
Prashanth Chandra
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic