I am trying to import javascript from a file into my jsp to be used as an in line script:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script>
<c:import url="/path/to/file.js" />
</script>
The above code works 99% of the time but I see a few errors like this in my tomcat logs:
Jun 20, 2013 1:25:33 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspTagException: 304 /path/to/file.js
at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:329)
at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:171)
at org.apache.jsp.WEB_002dINF.jsp.common.head.scripts_jsp._jspx_meth_c_005fimport_005f0(scripts_jsp.java:182)
at org.apache.jsp.WEB_002dINF.jsp.common.head.scripts_jsp._jspService(scripts_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jsp.WEB_002dINF.jsp.game_jsp._jspService(game_jsp.java:181)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
.......
I found the code that throws the above exception in ImportSupport.java:
// disallow inappropriate response codes per JSTL spec
if (irw.getStatus() < 200 || irw.getStatus() > 299) {
throw new JspTagException(irw.getStatus() + " " + stripSession(targetUrl));
}
So it looks like the servlet response code is 304.
The question is why? Is this a bug or am I missing something?
Update:
The problem seems to only occur if the incoming request has the If-Modified-Since header on
Update 2:
I solved the problem by removing the If-Modified-Since header from every request except for static files.