Struts Request Pb

Discussions

Web tier: servlets, JSP, Web frameworks: Struts Request Pb

  1. Struts Request Pb (3 messages)

    precisions :
    struts-config.xml:

    <action-mappings>
      <action name="RequestMenu" path="/RequestMenu"
        scope="request" type="web.actions.RequestMenuAction">
       <forward name="success" path="/pages/GenerateMenu.jsp"/>
       <forward name="fail" path="/pages/ErrorPage.jsp"/>
      </action>
    </action-mappings>


    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 :

    <FRAMESET rows="170,*">
      <FRAME NAME="banniere" SRC="about:blank">
      <FRAMESET COLS="150,*">
        <FRAME NAME="sommaire" SRC="/RequestMenu.do">
        <FRAME NAME="principal" SRC="about:blank">
      </FRAMESET>
    </FRAMESET>

    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.

    Please help

    Threaded Messages (3)

  2. re: Struts Request Pb[ Go to top ]

    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

        http://myserver.com/mywebapp

    the struts-config is setting up

        http://myserver.com/mywebapp/RequestMenu.do

    while the frameset is requesting

        http://myserver.com/RequestMenu.do


    Best,
    -Tim.
  3. something strange ![ Go to top ]

    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/.

    in login.jsp

    <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 !

    thanks
  4. something strange ![ Go to top ]

    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.

    -Tim.