• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding c:redirect and jsp:forward

 
saima kanwal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks ankit, the concept is now clear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic