0

I know that there are many similar issues in google, but I can't find one that help me..

When I include a css file in my JSP page it doesn't work:

<link rel="stylesheet" type="text/css" ../../css/car_rental.css">

If I try this:

<%@ include file="../../css/style.css"%>

it throws exception

/WEB-INF/view/../../css/style.css" file not found

How can I get rid of WEB-INF/view/ prefix?

P.S. my jsp page is located at /WEB-INF/view/ folder, and my css file at /css/ folder

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
VB_
  • 45,112
  • 42
  • 145
  • 293

2 Answers2

0

It looks like you are referencing your style sheet via a server side include. The <%@ include file="../../css/style.css"%> tag will inject the contents of the named file into the JSP containing the tag, as if it were copied and pasted. It is unlikely your JSP code will need to modify the contents of your cascading style sheet.

Try replacing the <%@ include file="../../css/style.css"%> tag with the HTML tag to include your stylesheet. <LINK href="/css/style.css" rel="stylesheet" type="text/css">

  • also doesn't work; but if I put directly on the page it works. P.S. I also tried to write full path: where http://localhost:8080/CarRental/css/car_rental.css is accessible via browser – VB_ Mar 30 '13 at 21:52
  • As I understand I should add something like resource mapping paths, and my app won't map url to .css files. But HOW? – VB_ Mar 30 '13 at 22:10
  • Andrew, can you please show the contents of the filesystem? for example: CarRental/ CarRental/css/style.css CarRental/WEB-INF/view/ – Mark Reimer Mar 30 '13 at 23:12
  • @AndrewMelnuk is the css file named style.css or car_rental.css? if the actual file name is car_rental.css use – Mark Reimer Mar 30 '13 at 23:15
  • it seems that my server use some old version of css: if I comment all car_rental.css my web-pages still remain formated (used old css). I tried to redeploy, reboot server and computer but ni result. How do delete old css from server? – VB_ Mar 30 '13 at 23:56
  • I noticed that even if delete my .css files, my app use some old .css version. So, I found answer to my own question: it's need to clear browser cache and the new .css version will work Thanks all for replies – VB_ Mar 31 '13 at 00:13
0

<%@ include file="XYZ" %> statically includes the content of your file as part of compiled servlet response. So even if it successfully finds the CSS file, its content will be treated as normal text and will be flushed in response. This means that your page will simply display the content of CSS and there wouldn't be any styling that would actually occur

You need to use the link tag in the head. It directs the browser to apply the style.

Also, relative paths do not work in include, as you can see from the error.

Use:

<link href="../../css/style.css" rel="stylesheet" type="text/css">
Cody Guldner
  • 2,888
  • 1
  • 25
  • 36
prashant
  • 1,805
  • 12
  • 19
  • I tried <%@ include file="XYZ" %> because my doesn't work. It seems my application map url path to my .css and can't find it. – VB_ Mar 30 '13 at 22:07
  • As I understand I should add something like resource mapping paths, and my app won't map url to .css files. But HOW? – VB_ Mar 30 '13 at 22:10
  • Ok try placing your css file within the same directory where your jsp is present (view directory) and then use . If this works then clearly the issue is with the way you are giving relative path. – prashant Mar 30 '13 at 22:16
  • It seems that my server use some old version of css: if I comment all car_rental.css my web-pages still remain formated (used old css). I tried to redeploy, reboot server and computer but ni result. How do delete old css from server? – VB_ Mar 30 '13 at 23:56
  • I noticed that even if delete my .css files, my app use some old .css version. So, I found answer to my own question: it's need to clear browser cache and the new .css version will work Thanks for replies – VB_ Mar 31 '13 at 00:13
  • @AndrewMelnuk seems like you were testing on IE. When developing web pages (even .Net web apps) you should try it on 2 or 3 different browsers. IMO you should make your tests on Chrome, Firefox and IE, being IE the most PITA. I had a similar issue long time ago, solved using this post: [How to disable cache in InternetExplorer 8](http://stackoverflow.com/q/2755800/1065197). – Luiggi Mendoza Mar 31 '13 at 02:41