Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

request & response

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!
 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic