| Author |
How to acheive Send Redirect in Struts
|
Parameswaran Thangavel
Ranch Hand
Joined: Mar 01, 2005
Posts: 485
|
|
hi all i need to redirect my application to completely different application. So i tried with response.sendRedirect("URL"); which fails completely. Since actionForward is expected by framework for every ActionServlet i donno what will be the flow of apllication? Any idea how can we redirect to different site in struts. And also what will happen to the Current session objects. will it get retained or get destroyed?
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
To forward to a different application, you need to: 1-Specify a forward. In the path, specify the full URL of the site including the "http://". Also specify redirect="true". 2-Simply find the forward using the ActionMapping object and return it from the execute() method of your Action class, just as you would with any other forward.
And also what will happen to the Current session objects. will it get retained or get destroyed?
Naturally, since you're moving to a completely different application, the new application knows nothing about your session or any other objects stored on your server. If after browsing the new application, the user navigates back to your site, the session and all other server-side objects will still be there.
|
Merrill
Consultant, Sima Solutions
|
 |
Parameswaran Thangavel
Ranch Hand
Joined: Mar 01, 2005
Posts: 485
|
|
Hi Is redirect can be acheived using only the action element instead of going to the execute method. sth like, <action forward="" redirect="true"/> instead of <action > <forward name="out" path="www.google.com" redirect="true" /> </action> i donno whether it is legal attribte, Since there is no logic or code done inside execute method other than setting the target say mapping.findforward("out").
|
 |
Eugene Abarquez
Ranch Hand
Joined: May 18, 2006
Posts: 211
|
|
Hello, I don't know if there is a policy against the revival of really old posts, but I have a follow-up question on this. What if the URL is not predetermined and is generated on the fly? You definitely can't specify it in the path attribute of your struts-config.xml file. Is there a way to do this in Struts? I hope somebody responds, Eugene
|
There's so much to learn in this industry, and not everybody has the necessary interest.
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8262
|
|
Originally posted by Eugene Abarquez: Hello, I don't know if there is a policy against the revival of really old posts, but I have a follow-up question on this.
Our policy is Dont Wake The Zombies Actually, in your case it's fine since you are expanding on the original question. I'm not sure about Struts, but HttpServletResponse has a sendRedirect method.
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Alaa Nassef
Ranch Hand
Joined: Jan 28, 2008
Posts: 460
|
|
According to the first question in the post, the sendReirect fails completely. So, is there another option?
|
Visit my blog: http://jnassef.blogspot.com/
|
 |
Eugene Abarquez
Ranch Hand
Joined: May 18, 2006
Posts: 211
|
|
Hi guys, sorry if I wake some zombies. I already found a turnaround for the problem. First, I saved the "dynamic" url in the session for later use in the Action object. Then, I just did the usual forward to another page called "redirect.jsp" from the Action object, using the predefined path attribute in the struts-config.xml file of course. Then in the redirect.jsp page, I placed a JSTL redirect tag and gave it the value of the "dynamic" url I saved from the session previously. Pretty hacky, but that solved the problem. Hope this helps somebody out too. Eugene
|
 |
Alaa Nassef
Ranch Hand
Joined: Jan 28, 2008
Posts: 460
|
|
|
Great solution. I would like to suggest to save the URL in the request rather than the session, so that i won't be there in the memory after the redirect.
|
 |
sai kumar
Ranch Hand
Joined: Mar 31, 2004
Posts: 72
|
|
Hello,
We are using the action mapping in struts config file to do a redirect.
The code snippet is like:
<forward name="changeLanguage" redirect="true" path="/changeLanguage.do" />
The redirect works fine but it is a temporary redirect (302).
We would like to change this to a permanent redirect (301). Do we have an option to configure that in the struts-config.xml.
Your reply will be appreciated.
Thanks
|
 |
 |
|
|
subject: How to acheive Send Redirect in Struts
|
|
|