You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mike La Budde <mi...@irista.com> on 2000/10/05 22:42:48 UTC

context-relative paths are painfull

OK, yes, I'm still wrestling with this issue.

Here's a snippet from my struts actions configuration file:

   <!-- ========== Global Forward Definitions 
============================== -->
   <global-forwards>
     <forward   name="logon"                path="/logon.jsp"/>
     <forward   name="success"              path="/pages/main/index.html"/>
     <forward   name="error"                path="/ErrorActionViewPage.do"/>
   </global-forwards>

   <!-- ========== Action Mapping Definitions 
============================== -->
   <action-mappings>

    <!-- ============================ Error BEGIN 
============================= -->

    <action path="/ErrorActionViewPage"
            type="com.irista.ui.web.fulfill.ErrorActionViewPage">
        <forward name="success"             path="/pages/main/error.jsp"/>
    </action>

    <action path="/ErrorDtlActionViewPage"
            type="com.irista.ui.web.fulfill.ErrorDtlActionViewPage">
        <forward 
name="success"             path="/pages/main/errorDetail.jsp"/>
    </action>

    <!-- ============================ Error END 
=============================== -->


If an error occurs I'm getting to /pages/main/error.jsp (thru' the global 
error forward /ErrorActionViewPage.do). This error page has a "View 
Details" button on it. However, attempting to view the details hangs or 
gets a 404 (page not found) error. Looking at the console window shows that 
it has somehow lost its context and it thinks its in the ROOT. Changing the 
above forward path for the ErrorDtlActionViewPage to 
path="/mycontextName/pages/main/errorDetail.jsp" works! Ouch! I'm totally 
confused by this behavior. (Not to mention that my earlier confusion 
(dismay?) at having to specify all paths as fully qualified context 
relative in the first place hasn't been satisfactorily cleared up. Hell, I 
got confused just re-reading that last sentence!)

Based on yesterday's exchanges between Craig & Colin I know I'm going to 
have even more fun when I get to the point where I'm configuring security 
for our apps! (Another opportunity...)

TIA,

Mike


Re: context-relative paths are painfull

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Mike et. al.,

A very important issue to remember when using Struts, or pretty much any other
servlet/JSP environment, is that the concept of "context relative" is only known
by the *server*, not by the *browser*.

Within the server, it is quite convenient to consistently treat all paths as
context relative.  That way, you can install your application on any context
path you want, and everything will still work.

The same is *not* true when you are generating hyperlinks in your output pages.
If you set up a hyperlink that ends up looking like this:

    <a href="/logon.jsp">Log on</a>

The browser interprets it as server-relative, not context-relative -- because it
has no idea what a context is.

If you are using multiple directory levels in your apps URI space (i.e. internal
slashes in the paths), the answer to this is that you need to make sure you
prefix context relative paths with the context path (i.e. the value returned by
request.getContextPath()) when generating hyperlinks in your generated HTML
pages.

Craig



Mike La Budde wrote:

> OK, yes, I'm still wrestling with this issue.
>
> Here's a snippet from my struts actions configuration file:
>
>    <!-- ========== Global Forward Definitions
> ============================== -->
>    <global-forwards>
>      <forward   name="logon"                path="/logon.jsp"/>
>      <forward   name="success"              path="/pages/main/index.html"/>
>      <forward   name="error"                path="/ErrorActionViewPage.do"/>
>    </global-forwards>
>
>    <!-- ========== Action Mapping Definitions
> ============================== -->
>    <action-mappings>
>
>     <!-- ============================ Error BEGIN
> ============================= -->
>
>     <action path="/ErrorActionViewPage"
>             type="com.irista.ui.web.fulfill.ErrorActionViewPage">
>         <forward name="success"             path="/pages/main/error.jsp"/>
>     </action>
>
>     <action path="/ErrorDtlActionViewPage"
>             type="com.irista.ui.web.fulfill.ErrorDtlActionViewPage">
>         <forward
> name="success"             path="/pages/main/errorDetail.jsp"/>
>     </action>
>
>     <!-- ============================ Error END
> =============================== -->
>
> If an error occurs I'm getting to /pages/main/error.jsp (thru' the global
> error forward /ErrorActionViewPage.do). This error page has a "View
> Details" button on it. However, attempting to view the details hangs or
> gets a 404 (page not found) error. Looking at the console window shows that
> it has somehow lost its context and it thinks its in the ROOT. Changing the
> above forward path for the ErrorDtlActionViewPage to
> path="/mycontextName/pages/main/errorDetail.jsp" works! Ouch! I'm totally
> confused by this behavior. (Not to mention that my earlier confusion
> (dismay?) at having to specify all paths as fully qualified context
> relative in the first place hasn't been satisfactorily cleared up. Hell, I
> got confused just re-reading that last sentence!)
>
> Based on yesterday's exchanges between Craig & Colin I know I'm going to
> have even more fun when I get to the point where I'm configuring security
> for our apps! (Another opportunity...)
>
> TIA,
>
> Mike

--
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat



Correction To: context-relative paths are painfull

Posted by Mike La Budde <mi...@irista.com>.
Please see interspersed comments.

At 10/05/2000 03:42 PM -0500, Mike La Budde wrote:
>OK, yes, I'm still wrestling with this issue.
>
>Here's a snippet from my struts actions configuration file:
>
>   <!-- ========== Global Forward Definitions 
> ============================== -->
>   <global-forwards>
>     <forward   name="logon"                path="/logon.jsp"/>
>     <forward   name="success"              path="/pages/main/index.html"/>
>     <forward   name="error"                path="/ErrorActionViewPage.do"/>
>   </global-forwards>
>
>   <!-- ========== Action Mapping Definitions 
> ============================== -->
>   <action-mappings>
>
>    <!-- ============================ Error BEGIN 
> ============================= -->
>
>    <action path="/ErrorActionViewPage"
>            type="com.irista.ui.web.fulfill.ErrorActionViewPage">
>        <forward name="success"             path="/pages/main/error.jsp"/>
>    </action>
>
>    <action path="/ErrorDtlActionViewPage"
>            type="com.irista.ui.web.fulfill.ErrorDtlActionViewPage">
>        <forward 
> name="success"             path="/pages/main/errorDetail.jsp"/>
>    </action>
>
>    <!-- ============================ Error END 
> =============================== -->
>
>
>If an error occurs I'm getting to /pages/main/error.jsp (thru' the global 
>error forward /ErrorActionViewPage.do). This error page has a "View 
>Details" button on it. However, attempting to view the details hangs or 
>gets a 404 (page not found) error. Looking at the console window shows 
>that it has somehow lost its context and it thinks its in the ROOT. 
>Changing the above forward path for the ErrorDtlActionViewPage to 
>path="/mycontextName/pages/main/errorDetail.jsp" works!

Sorry. Wrong, this isn't what we changed. We changed the link in the 
error.jsp page from /ErrorDtlActionViewPage.do to 
/mycontextName/ErrorDtlActionViewPage.do and then it worked....  I'm still 
just as confused, tho'. ;-)

>Ouch! I'm totally confused by this behavior. (Not to mention that my 
>earlier confusion (dismay?) at having to specify all paths as fully 
>qualified context relative in the first place hasn't been satisfactorily 
>cleared up. Hell, I got confused just re-reading that last sentence!)
>
>Based on yesterday's exchanges between Craig & Colin I know I'm going to 
>have even more fun when I get to the point where I'm configuring security 
>for our apps! (Another opportunity...)
>
>TIA,
>
>Mike