What you want to do is assign the * .css servlet mapping in the JSPServlet.
In most containers, you will see this mapping (this is from Glassfish, it has default-web.xml):
<servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>xpoweredBy</param-name> <param-value>true</param-value> </init-param> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping>
Here he declares the JSP servlet and maps it to "* .jsp". So, in this case, the JSP servlet link name is just "jsp".
So you would like to add:
<servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.css</url-pattern> </servlet-mapping>
When you do this, โsuddenlyโ ALL of your CSS files are essentially JSPs, so you can do whatever you want with them.
I don't know if "jsp" is the same for ALL containers, so your web.xml CANNOT be portable.
But that is the essence of what you want to do. If you do not want ALL CSS to be JSPs, you can put the files in your own directory and map them to the JSP servlet. Then ANYTHING you put into will be JSP (css, js, etc.).
source share