Women in Technology

Hear us Roar



Article:
  Two Servlet Filters Every Web Application Should Have
Subject:   If you are getting a 500 error due to a NPE...
Date:   2004-07-06 19:15:21
From:   willdenniss
If you are getting a 500 error due to a NPE, it may be because CacheFilter is trying to set a null mime type (it may be legal to set a null mime type - but some versions of Tomcat don't seem to like it).


In my own code running on Apache Tomcat/4.1.30, I got problems with my JSP's.


mt on this line was null:
String mt = sc.getMimeType(request.getRequestURI());


You can fix this by a simple check:
if (mt == null) {
mt = "text/html";
}


(setting mt to the empty sting "" may also work, I'm not sure).


Thanks for the great filter! I'm going to have to buy the book now :)


Will.