It feels logical that this problem should have been solved somehow already, given that thousands of developers have been using JSP every day, for years. But I've found only one solution that looks promising: http://pukkaone.github.com/2011/01/03/jsp-cross-site-scripting-elresolver.html.
I've given it a try and found that it basically works as expected. And the most important, you can override the escaping where needed, by using the custom tag. But there are 2 problems that prevented me from using it:
- The effect of this resolver is global (as expected), so you must remove existing escaping from every JSP where you have it, and re-test the whole application
- If you use <jsp:include> with parameters (and I use it a lot), you must override escaping of the parameter values, to avoid double escaping