• 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

Why is this code not working ?

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is a simple code where I want to know the tricks with sendRedirect. Why is this one not working ?
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
String pageName = "/first.jsp";
response.sendRedirect(pageName);
String s = "Maya";
if(s.equals("Maya"))
response.sendRedirect("/second.jsp");
else{
response.sendRedirect("/third.jsp");
}
}
This code pops up first.jsp, but is not doing any further checkings.
Please clarify this to me.
My environment is
Windows 2000
Apache Web server
Apache JServ 1.1
JSDK2.0
Thanks,
Maya
[This message has been edited by maya menon (edited August 09, 2001).]
[This message has been edited by maya menon (edited August 09, 2001).]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the HttpServletResponse documentation on sendRedirect
After using this method the response should be considered to be committed and should not be written to.
Bill

------------------
author of:
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,
Thanks for the reply.
Is the same rule appliable for RequestDispatcher Interface also ?
BTW, Your Exam Cram book was very useful for me in preparing for my certification. I bought it a week before my exam, went through the chapters and attempted the mock exam.
I scored 82% in my SCJP. Many thanks for the book.
Now I am heading towards IBM OOAD exam.
Any advices for that welcome!!!
Thanks,
Maya
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Maya!
In request Dispatcher control comes back to ur servlet. But remember if u use forward it won't wait for first.jsp action to be complete where as if u include it will do...
Rgds
Manohar
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manohar,
Thanks for the response.
So, if I can use JSDK2.1, then with the above code if I replace sendRedirect by RequestDispatcher, will it work ?
Thanks,
Maya
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes! it will work
 
reply
    Bookmark Topic Watch Topic
  • New Topic