Web tier: servlets, JSP, Web frameworks: Struts Request Pb
<action name="RequestMenu" path="/RequestMenu"
<forward name="success" path="/pages/GenerateMenu.jsp"/>
<forward name="fail" path="/pages/ErrorPage.jsp"/>
If I type /RequestMenu.do in the IExplorer Address Bar Struts correctly call the RequestMenuAction (it works).
But if I want the view associated with this action to be in a FRAME I do like this :
<FRAME NAME="banniere" SRC="about:blank">
<FRAME NAME="sommaire" SRC="/RequestMenu.do">
<FRAME NAME="principal" SRC="about:blank">
But Struts does not understand the request and my app Server (Tomcat) show an unavailable ressource error for "/RequestMenu.do" (.do!? shouldn't be viewed by tomcat?). The Struts servlet seems not to intercept the request.
Just a thought...
Remember that /RequestMenu in the struts-config.xml is relative to your web application root.
In the frameset, the /RequestMenu.do is relative to the server root.
So, if your web application root is
the struts-config is setting up
while the frameset is requesting
thanks a lot, it works, but this means I have to write full path to the resource at each time ?
There's something I don't understand (it's the same for any resource images/jsp...) :
my login.jsp page is located in /webApp/pages/login.jsp
my images are in /webApp/pages/images/.
<IMG src="images/APicture.gif"> works fine whereas
in RequestMenuView.jsp (it's the "RequestMenu.do" action's view) that is also located in /webApp/pages
if I write <IMG src="images/APicture.gif"> it doesn't work. I have to write "/webApp/pages/images/APicture.gif"
The only difference is that RequestMenuView.jsp is forwarded from a struts action. So does it mean I have to write different paths in case I am in a struts'view or not ? Perhaps my struts config is bad ? Do I have to set the struts document root ? I'm a little lost !
Normally, a relative link to an image, file, whatever resolves based on the original URL of the request. That's why if you directly access "/webApp/pages/login.jsp" you get "/webApp/pages/images/APicture.gif".
However... remember in Struts, your original request is made to the front controller servlet (eg. "something.do"). The front controller maps that request to an Action... and based on the result of the action, forwards onto the appropriate JSP view.
So since our original request URL was "/webApp/RequestMenu.do", the image link will actually resolve to "/webapp/images/APicture.gif".
That said, there is an easy solution. The HTML spec provides a <base /> tag which tells the browser "all relative URLs resolve to this specified base URL, instead of the URL of the original request". Struts provides an <html:base /> tag in its HTML tag library. This will produce an HTML base tag that uses the URL of the JSP you forwarded to.
You can consult the Struts documentation on <html:base /> for more details. But if you put that in your HTML <head>... that should fix all your relative links.