• Post Reply Bookmark Topic Watch Topic
  • New Topic

request & response

 
navat venu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ,pg#137 it said that "you can't do a sendRedirect() after writing to the response"

but when i run code1 the following code in servlet it gave no error & done the redirect

code1:
-------------------------------------------------------------------------
PrintWriter out = res.getWriter();
String name=req.getParameter("param1");
String client=req.getHeader("User-Agent");
out.println("<html>"+"<body>"+client+"venu Navat"+"</html>"+"</body>");
res.sendRedirect("http://www.google.com");
-------------------------------------------------------------------------

when i run code2 in servlet it gave no error & displayed response & didn't redirect

code2:
-------------------------------------------------------------------------
PrintWriter out = res.getWriter();
String name=req.getParameter("param1");
String client=req.getHeader("User-Agent");
out.println("<html>"+"<body>"+client+"venu Navat"+"</html>"+"</body>");
out.flush();
res.sendRedirect("http://www.google.com");
-------------------------------------------------------------------------

please clarify !!
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The details of exception are visible in log files.
Check them
 
navat venu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the log files!
And you are true, i could see the "IllegalStaeException" for code2 in log file.

Thanks shivani!!
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!