This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Why is this code not working ?  RSS feed

 
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).]
 
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
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!