Elad Benda Elad Benda - 2 months ago 9
CSS Question

how to relate to a relative css of master page?

I have few html pages which are generated by my java application:

html_pages/
|
----> landin_page.html

html_pages/details
|
----> index1.html

html_pages/more_details
|
----> index2.html

html_pages/css
|
----> master_page.css


I want to reference the master_page.css in the header of each html page.

how can i relate to it?

I thought to do it using absolute path, but I get 404

<link rel="stylesheet" href="/html_pages/css/master_page.css">

Pat Pat
Answer

Using ${pageContext.request.contextPath} is the standard way to mention the full path.

<link rel="stylesheet" href="${pageContext.request.contextPath}/css/delta_samples.css">

Adding ${pageContext.request.contextPath} does the trick.

Adding "../" also works but is not recommended as best practices !! And code might break at times if this is used.

Comments