Search code examples
cssjspembedscriptlet

Using scriptlets inside a .CSS file?


suppose I have an inline styling such as below inside a .JSP file:

<style>
.bg{
    background-color: <%=application.getAttribute("bgcolor").toString()%>
}
</style>

What if I want to make it an external .CSS file instead of using inline styling? I tested it and it doesn't work properly?

Many thanks!


Solution

  • The .jsp files are compiled by the container, so you have to write the you css class in .jsp file make sure the response content type is text/css and add the JSP file to your html like below.

    <link rel="stylesheet" href="filename.jsp">