The file extension is in fact irrelevant. The key is the HTTP Content-Type
header. The browser uses this information to treat the response in an appropriate manner.
Put this in top of your to-be-CSS JSP file:
<%@ page contentType="text/css" %>
That's it.
If you leave the manual setting of the HTTP Content-Type
header away, then the job of setting the Content-Type
header will be taken over by the servletcontainer/webserver. This part is then sniffing the file extension to set the appropriate header.
Update: as per your update, you want to use the .css
extension anyway to take benefit of IDE's highlighting and autocompletion. Then there's another way: map the CSS file on the servlet-name
of the JspServlet
as it is definied in the particular servletcontainer. In case of Tomcat, it's usually jsp
.
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/style.css</url-pattern>
</servlet-mapping>
You should however take into account that the behaviour of your webapp will now be dependent of the servletcontainer in question. There may exist servletcontainers which doesn't use jsp
as servlet-name
.