struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: context-relative paths are painfull
Date Thu, 05 Oct 2000 21:05:10 GMT
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



Mime
View raw message