0

I have 2 pages:

Added css in login.jsp using c:url:

<c:url value="css/style.css"/>

When I open 1st link - everything works well. I tried to add the same style.css file to manage.jsp (2nd URL), but when I open 2nd link - css is not included. In Page Source I have:

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

How to define to take style.css from the root of URL (http://local.host:8080/test) ?

1
  • clear the cache and try again. Commented Mar 19, 2014 at 8:32

2 Answers 2

2

I think it is, because the specified path is relative to the current page (login is at an other level of path-nesting* than admin/manage).

A trivial but bad solution would be adding ../ for the css of admin/manage. But this soultion has the drawback, that you always need to adjust the ../ when you change the level of path-nesting* for an page.

To overcome this problem, make the path in the c:url-tag start with an /! (this make the tag aware that the url is context relative (relative to http://local.host:8080/test/), and the tag will automatically addhttp://local.host:8080/test` in front.

<c:url value="/css/style.css"/>

will be rendered to : http://local.host:8080/test/css/style.css

For the link use this way

<c:url value="/css/style.css" var="cssUrl"/>
<link rel="stylesheet" type="text/css" href="${cssUrl}"/>

*I do not know the correct term for "path nesting" at the moment - fell free to change it

Sign up to request clarification or add additional context in comments.

Comments

0

Order of attribute might be the problem. Correct the order

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.