Does the inclusion of a .css file in JSP cause any problem?
Created May 4, 2012
Sean Kelly That depends on what you mean by "inclusion."
The JSP processor copies non-scriptlet and non-JSP tags to the servlet output stream verbatim, including references to cascading stylesheets. For example, if your .jsp
file contains this line:
<link href="/mine.css" rel="stylesheet">then that line goes to the client unchanged, causing no problem.
If you mean you wish to include the contents of a .css
file in a .jsp
file with the <jsp:include>
mechanism, you can do that, too. But the JSP file should itself become a cascading stylesheet when processed, since the CSS syntax isn't compatible with HTML syntax. That is, you'd do something like this:
<%@ page language="java" contentType="text/css" %> <jsp:include page="/included.css"/> BODY { font-weight: bold; }Here, the JSP file contains some CSS syntax, and uses the JSP include tag to include the contents of another
.css
file. After processing, the client sees the complete file as a cascading stylesheet, thanks to the text/css content type.