| Author |
how to forward from the root
|
Sarah ss
Greenhorn
Joined: Jul 28, 2006
Posts: 3
|
|
Hey guys This is the issue I have. I have several apps running on different context. Like the start pages would be : http://localhost:8080/music/songs/start.do http://localhost:8080/movies/startMovie.do Now whenever I try to forward, it is always relative to the context. Like from start.do, if I forward, it will always look inside http://localhost:8080/music/songs/ Similarly from startMovie.do, if I forward, it will look in http://localhost:8080/movies/ But what if I want to forward to a resource at the root level http://localhost:8080/error.html I know I can do something like this from StartAction (start.do) ActionForward forward = new ActionForward(); forward.setPath("../../error.html"); forward.setRedirect(true); return forward; And from startMovie.do ActionForward forward = new ActionForward(); forward.setPath("../error.html"); forward.setRedirect(true); return forward; But this wont work. Because I wont know whether to use a ../ or a ../../ Isnt there a simple way to forward from the root level. Thanks Sarah
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
What is your web context root? Is it "/"? Are we talking about a single Struts application or multiple applications? If it's a single application, are there multiple modules? [ August 02, 2006: Message edited by: Merrill Higginson ]
|
Merrill
Consultant, Sima Solutions
|
 |
Gilbert johnson
Ranch Hand
Joined: Jul 10, 2005
Posts: 45
|
|
Thanks for your reply. There are multiple struts applications. Well Actually I'm not sure whether you call them as different struts modules or struts applications. Say there is a domain called www.abc.com Now under this domain several departments have their own struts websites. Like department1's website is accessed through www.abc.com/department1/something Similarly department2's website is accessed through www.abc.com/department2/dept2/something (it might be like 2 levels down). So the root is www.abc.com So in the root say we have a file like www.abc.com/error.html And I want to forward to this error.html, from www.abc.com/department1/something or from www.abc.com/department2/dept2/something But I dont want to forward using absolute path like ActionForward forward = new ActionForward(); forward.setPath("http://www.abc.com/error.html"); forward.setRedirect(true); return forward; Thanks
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
Yes, it's possible to set up a forward to a "root" page like this. It's still considered a forward outside the application, though. Because of this, you cannot use a context relative reference. You must enter the full URL. So, here is the forward you'd set up: <forward name="error" path="http://www.abc.com/error.html" redirect="true" />
|
 |
Gilbert johnson
Ranch Hand
Joined: Jul 10, 2005
Posts: 45
|
|
Thanks Merill The problem is I'm not going to be hardcoding the forwards in the struts-config. If this was not a struts application, is it possible to redirect without using absolute path, by using requestDispatcher.sendRedirect. Thanks
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
|
There's no way around it. Even with response.sendRedirect() you have to specify the full URL if you're going outside the current application.
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
|
One possible workaround, though, would be to use the HttpServletReqeust object's getRequestURL() method to get the URL sent to the web container to reach the current action. You could easily develop a utility that would parse through this String, extract the server portion of the URL, and append it to the relative path you might send in as a parameter.
|
 |
Gilbert johnson
Ranch Hand
Joined: Jul 10, 2005
Posts: 45
|
|
thanks for your help merill appreciate it
|
 |
 |
|
|
subject: how to forward from the root
|
|
|