In every webapplication i have used forward. i want to know the scenario where i can use only redirect not forward or where redirect will be advantageous to use if compare to forward?开发者_开发知识库
An example: a web gallery. The client upload pictures then set some metadata on the /createGallery
url and click the OK button which calls a servlet. The servlet create a new record in the database with the given metadata and generate a random key. Then it redirects the browser to the /gallery.jsp?secretKey=<randomkey>
url. After that the user could copy the url from the address bar of the browser and could send his friends or share on Twitter, Facebook etc. or just save as a bookmark. If you use forward the url in the address bar remains /createGallery
and the friends will not see the cute pictures. The service also could be a custom RSS channel, a calendar (Doodle also use this kind of redirects), a web forum, etc.
Of course a "workaround" is using forward and put the /gallery.jsp?secretKey=<randomkey>
link to the generated page but it's ugly a little bit and has all the disadvantages which @BalusC mentioned.
精彩评论