Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is this code not working ?  RSS feed

 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • 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).]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Yes! it will work
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!