Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Patrick,

On 9/18/2011 12:55 PM, Patrick Flaherty wrote:
All the skins work except image references in the style sheet (css)
 cannot be found. Yet images referenced in the jsps are found!

Your JSPs are dynamic and include the webapp prefix, since you
(evidently) properly prefixed and encoded your URLs (good for you).
Your CSS files are not dynamic and, unless you put the prefixes on
there, your images will not be found. Note that any included CSS files
will also not be found (i.e. CSS includes CSS) for the same reason.

Is there a hard and fast rule here I’m missing. What’s best
practice ?

I dunno about best practice, but we do what you are doing: put the
webapp prefix into the CSS files and don't forget to change it if you
re-locate the webapp to another prefix (which pretty much never happens).

There are other options that I can think of off the top of my head:

1. Use the HTML <base /> tag to set the base URL in your dynamic pages.
   Any relative URLs will be relative to that base. This may ruin
   the URLs that you have carefully and properly prefixed and escaped
   in your JSPs, but it's an option.

2. Make your CSS files dynamic: have Tomcat serve them and perform the
   context-path translation on the fly.

3. Use server-side content filtering for .css files. This is roughly
   the same as #2 except that you would use a simpler string-replace
   mechanism instead of a fully-dynamic content-generation technology
   (such as JSP, etc.).

4. Write a bunch of URL rewrite rules that match the CSS/image files
   that you know aren't in the "right" place. This is going to be
   a pain in the neck.


And any of the above will cause problems if you want to give your app to a graphic designer, who will move these pages to his workstation and try to work on them.

I'm sure there are other options.


What I do not understand here (maybe due to my lack of knowledge of JSP pages logic) is why one would need to "fix" anything, if the links are correctly spelled-out in the first place, taking into account how a browser handles absolute/relative links.

e.g. imagine this structure :

(catalina_base)/webapps/
                       myapp/ (contains *.JSP pages)
                            /images/ (contains images)
                            /css/ (contains stylesheets)

If the JSP pages contain links to stylesheets located in "myapp/css", their reference should say : href(or src)="css/name-of-stylesheet.css" If the css files in turn contain links to images, they can be expressed as : src="../images/some-image.jpg"
And so on.
If you then move "en block" the whole "myapp" somewhere else, all links should keep working just fine.

Or does something there not work in a webapp/JSP context ?



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to