Why use 'redirect=true' in struts 1.* forward?

妖精的绣舞 提交于 2019-11-29 21:31:45

it prevents the 'double submit problem'

Never show pages in response to POST

Always load pages using GET

Navigate from POST to GET using REDIRECT

more on this here and here

Redirect sends a response to the browser that forces the browser to make a new request. From the server point of view, the browser just makes a new request (albeit autmatically). Some characteristics of a redirect:

  • The existing parameters and attributes are disposed, a new request is formed with the parameters you specify in the URL.
  • The new URL is visible in the browser, the user can bookmark it.
  • It takes a trip to the browser and back, so it can be slower.

A forward happens on the server. The browser is not involved in this. Some characteristics of the forward:

  • New parameters are added or overwrite existing parameters. So the existing parameters cannot be removed from the request.
  • Stuff can be added in request context, it will remain available. You can pass information in this way.
  • The URL is not changed in the browser, for the browser the original address remains intact.
  • You can only forward to another URL in the same application.

So it depends on what you want to accomplish. A forward is generally spoken faster. But if the user should be able to bookmark the new location, it is not an option.

Mohit Singh

If you specify redirect="true", Struts uses a client-side redirect [response.sendRedirect()]. The JSP will be invoked by a new browser request, and any data stored in the old request will be lost.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!