I’m working on a web application using Java code, I had changed my code by making each page start from a servlet class.
Java code in servlet “indexServlet”:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
DataGathering dBConnector = new DataGathering();
List<Long> lstDetailVewOID;
lstDetailVewOID = dBConnector.getDetailVewOID();
request.setAttribute("detailVewLst", lstDetailVewOID);
// pass the list to jsp page.
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
Since then the CSS code stopped working, and it gives me this error :
Resource interpreted as Stylesheet but transferred with MIME type
text/html: “http://localhost:8080/firstApplication/Style-Sheet/Template-Style.css”.
When tracing the code, I found that by running the doGet() method inside the servlet class, it’s call the page and run it, then get back to the servlet again to close the method, I guess the error because of this procedure but am not sure and I can’t solve it.
When searching through the internet i figured that the type should be text/css but i already did that, and the same CSS file was working find before changing the code.
calling the CSS file inside the jsp page:
<link href="Style-Sheet/Template-Style.css" rel="stylesheet" type="text/css">
Edit:
web.xml mapping:
<servlet>
<servlet-name>Index</servlet-name>
<servlet-class>com.Teklabz.Servlets.IndexServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Index</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I’m think you return static resources like css and images through your servlet. This is bad itself, but if you do, you need set right mime type in response headers. Actually i’m think you should change servlet-to-url mapping from /* to somewhat like /*.jsp, so, all other static resources will be handled by your tomcat/jetty, they do it right.