You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kristian Rink <kr...@zimmer428.net> on 2005/11/28 13:27:39 UTC

css and images (stupid question?)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all;

playing around with tomcat in order to both learn using the package and
create a small web site there, I'm currently left with a problem which,
though probably being small (and not really related to tomcat), keeps
bugging me:

I'm trying to do the visual stuff of my jsp using a css style file,
which is good, so far. Within the css file, I'm using images for
backgrounds etc like that:


background: #fff url(/images/bg_header_blau.jpg) no-repeat top left;


My problem, right now, is where to put the images within the web
application so they're actually found when displaying the page.
Initially, I created a folder "images" within my web application and
referred to the images using url(images/...) with relative path names,
which didn't work. Also tried to place the images folder inside
$CATALINA_HOME/webapps and then using absolute image urls (/image/...),
which also didn't work.

So, where's the magic? I've always been through some tougher moments
with css and images while dynamically generating content, but right now
I feel really helpless about that. Can someone enlighten me?

Cheers and thanks,
Kris



- --
Kristian Rink *  http://zimmer428.net * jab: kawazu@jabber.ccc.de
icq: 48874445 *  fon: ++49 176 2447 2771

"Be yourself the kind of change you want to see in this world." (Gandhi)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFDive4cxBAPOA1m6wRAnRxAJ90PaDKZsQQDo3M4CCd7WV5Syi/MgCdGhbs
hobJ1TqkErAqjLxZc6gV0kM=
=O7hF
-----END PGP SIGNATURE-----

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


Re: css and images (stupid question?)

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
Kristian Rink wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hi all;
>
>playing around with tomcat in order to both learn using the package and
>create a small web site there, I'm currently left with a problem which,
>though probably being small (and not really related to tomcat), keeps
>bugging me:
>
>I'm trying to do the visual stuff of my jsp using a css style file,
>which is good, so far. Within the css file, I'm using images for
>backgrounds etc like that:
>
>
>background: #fff url(/images/bg_header_blau.jpg) no-repeat top left;
>
>
>My problem, right now, is where to put the images within the web
>application so they're actually found when displaying the page.
>Initially, I created a folder "images" within my web application and
>referred to the images using url(images/...) with relative path names,
>which didn't work. Also tried to place the images folder inside
>$CATALINA_HOME/webapps and then using absolute image urls (/image/...),
>which also didn't work.
>
>So, where's the magic? I've always been through some tougher moments
>with css and images while dynamically generating content, but right now
>I feel really helpless about that. Can someone enlighten me?
>  
>

Well, your basic problem is that relative paths will not work, since 
pages can be in different directories. Absolute path has one problem, 
your application can be deployed under different paths. That problem is 
easy to solve, HttpServletRequest.getContextPath() will give you the 
deployment path. Just paste it on your desired CSS location, like this:

css.jsp
-------
...

background: #fff url(<%= request.getContextPath() %>/images/bg_header_blau.jpg) no-repeat top left;

or, if you're using JSP 2.0

background: #fff url(${request.contextPath}/images/bg_header_blau.jpg) no-repeat top left;

...
-------

Nix.

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