4

I would like to perform a redirection for my JSP page, which the URL will be changed to /folder/mypage.jsp, without losing my request attributes.

Is there any way I can perform this kind of redirection in Struts 2?

<result type="redirect">/folder/mypage.jsp</result>
Roman C
  • 49,761
  • 33
  • 66
  • 176
ilovetolearn
  • 2,006
  • 5
  • 33
  • 64
  • 1
    add dynamic parameters to the result or store request attribute values to the session, if you use request scoped variables then better redirect to the action where you can add these variable to the request – Roman C Sep 06 '16 at 07:40
  • Roman, Thanks for the suggestion! – ilovetolearn Sep 06 '16 at 08:39
  • 1
    Any time there's a new request, by definition you lose the current request's attributes/parameters. You need to send them again--there are multiple ways this can be accomplished. It may also be an [XY problem](http://xyproblem.info/) in that strictly "keeping" request attributes may be more trouble than it's worth. – Dave Newton Sep 06 '16 at 10:41
  • you are right. I am going against how the implementation works. – ilovetolearn Sep 06 '16 at 12:38

1 Answers1

3

A dispatcher result type is what you need. When you perform redirection to a JSP page using this type of result the request is dispatched to the resource by forwarding request to the new request. A dispatcher result type is used by default.

<result>/folder/mypage.jsp</result>

In this way you "keep" all attributes from the previous request. Then Struts filter is able to delegate JSP pages to a default servlet instead of action execution, however the action context is created, so you can use Struts tags in JSP.

Roman C
  • 49,761
  • 33
  • 66
  • 176