Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
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
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!