Skip to main content

Posts

Showing posts with the label groovy

How to make simplest servlet filter respect setted character encoding

Gentlemen, it feels like I'm stuck. I'm trying to write the simplest servlet Filter (and deploy it to tomcat). It's a groovy code, but actually I'm heavily usin java approaches here, so it is almost copypaste, that's the reason I've added java tag as well. My question is - how can I insert UTF-8 string to filter? Here is the code: `public class SimpleFilter implements javax.servlet.Filter { ... public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException { PrintWriter out = response.getWriter() chain.doFilter(request, wrapResponse((HttpServletResponse) response)) response.setCharacterEncoding('UTF-8') response.setContentType('text/plain') def saw = 'АБВГДЕЙКА ЭТО НЕПРОСТАЯ ПЕРЕДАЧА ABCDEFGHIJKLMNOP!!!' def bytes = saw.getBytes('UTF-8') def content = new String(bytes,