You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by William BC Crandall <bc...@earthlink.net> on 2004/07/11 06:35:24 UTC

Finding CSS files in webapp

Greetings fellow Tomcat dancers,

Been losing cycles in a gumption trap, trying to hook a CSS file 
up to XSLT-generated XHTML pages. Many thanks to whomever sees 
my obvious error.

If I hardwire the full-path filename of my development environment 
into the XSLT file, all works as hoped/planned/dreamed. But all 
other techniques I've tried fail. 


Tomcat: 5.0.19. Webapp name: nrd.

WAR layout:

  |-nrd
    |-css/nrd.css
    |-images/
    |-Meta-inf/
    |-Web-inf/
      |-classes/
      |-dtd/
      |-lib/
      |-xsl/
      |-web.xml

web.xml:

    <web-app>
      <servlet>
        <servlet-name>
          controller
        </servlet-name>
        <servlet-class>
          org.apnp.nrd.ControlServlet
        </servlet-class>
      </servlet>

      <servlet-mapping>
        <servlet-name>
          controller
        </servlet-name>
        <url-pattern>
          /*
        </url-pattern>
      </servlet-mapping>
    </web-app>

XSLT source that works:

    <head>
      <meta http-equiv="Content-Type"
            content="application/xhtml+xml; charset=utf-8"/>
    
      <link rel="stylesheet" type="text/css"
            href="C:\Apache\Tomcat\Tomcat50\webapps\nrd\css\nrd.css"/>
    </head>


Versions of CSS href that do not work:

            href="css/nrd.css"/>
            href="/css/nrd.css"/>
            href="./css/nrd.css"/>
            href="nrd/css/nrd.css"/>
            href="/nrd/css/nrd.css"/>
            href="./nrd/css/nrd.css"/>


I've also tried setting a global XSLT parameter:

      <xsl:param name="rootDir" select="'../docroot'"/>

and calling that:

      <link rel="stylesheet" type="text/css"
            href="{$rootDir}css/nrd.css"/>

which results in a known unsuccesful link:

            href="/nrd/css/nrd.css" 


Please, if you can, tell me what obvious thing I've missed.

Thanks for any suggestions.


Best wishes,

William BC Crandall
bc.crandall [around] earthlink.net


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Finding CSS files in webapp

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
Peter Rossbach wrote:
> Hey,
> 
> I think your browser is the problem. Generate absolute css link that help
> 
> <% String url = request.getScheme() + "://" + request.getServerName() + 
> ":" + request.getServerPort() + request.getContextPath() ; %>
> 
>      <link rel="stylesheet" type="text/css"
>            href="<%=url%>/css/nrd.css" />

Or a relative link, which might get some complaints from the browser (my 
Dreamweaver always complains if the relative path goes outside some 
scope). The original poster has failed to give us an important clue. How 
is XHTML file getting generated? To what URI it responds?

That URI is what browser sees and a LINK's "href" is relative to that base.

So if you have an URI: http://server.domain.com/nrd/mypath/file.xhtml, 
which gets mapped via "Controller" to XSLT processing engine and 
generates a XHTML document in response, the the "href" of "<link ...>" 
should be "../css/nrd.css".

Nix.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Finding CSS files in webapp

Posted by Peter Rossbach <pr...@objektpark.de>.
Hey,

I think your browser is the problem. Generate absolute css link that help

<% String url = request.getScheme() + "://" + request.getServerName() + 
":" + request.getServerPort() + request.getContextPath() ; %>

      <link rel="stylesheet" type="text/css"
            href="<%=url%>/css/nrd.css" />

regards
peter

William BC Crandall schrieb:

>Greetings fellow Tomcat dancers,
>
>Been losing cycles in a gumption trap, trying to hook a CSS file 
>up to XSLT-generated XHTML pages. Many thanks to whomever sees 
>my obvious error.
>
>If I hardwire the full-path filename of my development environment 
>into the XSLT file, all works as hoped/planned/dreamed. But all 
>other techniques I've tried fail. 
>
>
>Tomcat: 5.0.19. Webapp name: nrd.
>
>WAR layout:
>
>  |-nrd
>    |-css/nrd.css
>    |-images/
>    |-Meta-inf/
>    |-Web-inf/
>      |-classes/
>      |-dtd/
>      |-lib/
>      |-xsl/
>      |-web.xml
>
>web.xml:
>
>    <web-app>
>      <servlet>
>        <servlet-name>
>          controller
>        </servlet-name>
>        <servlet-class>
>          org.apnp.nrd.ControlServlet
>        </servlet-class>
>      </servlet>
>
>      <servlet-mapping>
>        <servlet-name>
>          controller
>        </servlet-name>
>        <url-pattern>
>          /*
>        </url-pattern>
>      </servlet-mapping>
>    </web-app>
>
>XSLT source that works:
>
>    <head>
>      <meta http-equiv="Content-Type"
>            content="application/xhtml+xml; charset=utf-8"/>
>    
>      <link rel="stylesheet" type="text/css"
>            href="C:\Apache\Tomcat\Tomcat50\webapps\nrd\css\nrd.css"/>
>    </head>
>
>
>Versions of CSS href that do not work:
>
>            href="css/nrd.css"/>
>            href="/css/nrd.css"/>
>            href="./css/nrd.css"/>
>            href="nrd/css/nrd.css"/>
>            href="/nrd/css/nrd.css"/>
>            href="./nrd/css/nrd.css"/>
>
>
>I've also tried setting a global XSLT parameter:
>
>      <xsl:param name="rootDir" select="'../docroot'"/>
>
>and calling that:
>
>      <link rel="stylesheet" type="text/css"
>            href="{$rootDir}css/nrd.css"/>
>
>which results in a known unsuccesful link:
>
>            href="/nrd/css/nrd.css" 
>
>
>Please, if you can, tell me what obvious thing I've missed.
>
>Thanks for any suggestions.
>
>
>Best wishes,
>
>William BC Crandall
>bc.crandall [around] earthlink.net
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Finding CSS files in webapp

Posted by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk>.
Hello

I have no knowledge of XSLT-generated XHTML pages, but I make extensive use
of the header 'BASE' tag and my CSS files always come through, so you may
want to consider that option.


<html>

    <head>
        ...
        <base href="https://www.my-domain-name.com/my-web-app-name/">
        <link rel="stylesheet" type="text/css" href="asset/css/my.css">
        ...
    </head>

<body>

...


Notice the trailing forward-slash in the BASE tag hyperlink reference. This
means that all other hyperlink references are stated as being relative to
that, and must NOT start with a leading forward-slash.

I specify the BASE tag using a custom tag that retrieves the base hyperlink
value from a context initialisation parameter (specified in the deployment
descriptor).

Using the BASE means that *all* my URL references are relative - and it has
not let me down yet.

Good luck!

Harry Mantheakis
London, UK



> 
> Greetings fellow Tomcat dancers,
> 
> Been losing cycles in a gumption trap, trying to hook a CSS file
> up to XSLT-generated XHTML pages. Many thanks to whomever sees
> my obvious error.
> 
> If I hardwire the full-path filename of my development environment
> into the XSLT file, all works as hoped/planned/dreamed. But all
> other techniques I've tried fail.
> 
> 
> Tomcat: 5.0.19. Webapp name: nrd.
> 
> WAR layout:
> 
> |-nrd
>   |-css/nrd.css
>   |-images/
>   |-Meta-inf/
>   |-Web-inf/
>     |-classes/
>     |-dtd/
>     |-lib/
>     |-xsl/
>     |-web.xml
> 
> web.xml:
> 
>   <web-app>
>     <servlet>
>       <servlet-name>
>         controller
>       </servlet-name>
>       <servlet-class>
>         org.apnp.nrd.ControlServlet
>       </servlet-class>
>     </servlet>
> 
>     <servlet-mapping>
>       <servlet-name>
>         controller
>       </servlet-name>
>       <url-pattern>
>         /*
>       </url-pattern>
>     </servlet-mapping>
>   </web-app>
> 
> XSLT source that works:
> 
>   <head>
>     <meta http-equiv="Content-Type"
>           content="application/xhtml+xml; charset=utf-8"/>
>   
>     <link rel="stylesheet" type="text/css"
>           href="C:\Apache\Tomcat\Tomcat50\webapps\nrd\css\nrd.css"/>
>   </head>
> 
> 
> Versions of CSS href that do not work:
> 
>           href="css/nrd.css"/>
>           href="/css/nrd.css"/>
>           href="./css/nrd.css"/>
>           href="nrd/css/nrd.css"/>
>           href="/nrd/css/nrd.css"/>
>           href="./nrd/css/nrd.css"/>
> 
> 
> I've also tried setting a global XSLT parameter:
> 
>     <xsl:param name="rootDir" select="'../docroot'"/>
> 
> and calling that:
> 
>     <link rel="stylesheet" type="text/css"
>           href="{$rootDir}css/nrd.css"/>
> 
> which results in a known unsuccesful link:
> 
>           href="/nrd/css/nrd.css"
> 
> 
> Please, if you can, tell me what obvious thing I've missed.
> 
> Thanks for any suggestions.
> 
> 
> Best wishes,
> 
> William BC Crandall
> bc.crandall [around] earthlink.net
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org