• 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

regarding c:redirect and jsp:forward

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code is written by me while comparing the difference in the behavior of redirect and forward:

MyPage.jsp is as follows:



and page2.jsp is as follows:




and i found the result:

Page 2 JSP
This is the forwarded page. null




which means that when we redirect a request to another page, the request attributes are not accessible from the redirected page. I am not sure whether I am correct or not , or am I making some mistake with the coding??

Now if I change my MyPage.jsp as follows:



now the result is :

Page 2 JSP
This is the forwarded page. saimakanwal



it means that if we forward a request , it retains all the request attributes. Am I correct with this conclusion or not? or am i making some mistake with the coding . Anyone please confirm and clarify.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use c:redirect, the browser is asked to send another request to the new location. So the browser makes a new request to the redirected page. Since the new page is requested with a new request, the request attributes of the previous request are gone. But when we use jsp:forward, the new page is requested on the server side using RequestDispatcher mechanism. Since a new request is not made in this case, so the request attributes are retained...
 
saima kanwal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ankit, the concept is now clear.
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic