Created
May 30, 2013 19:01
-
-
Save Crydust/5680246 to your computer and use it in GitHub Desktop.
CharacterEncodingFilter for java EE 6 (I can't believe I'm writing this AGAIN)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fileupload; | |
import java.io.IOException; | |
import javax.servlet.Filter; | |
import javax.servlet.FilterChain; | |
import javax.servlet.FilterConfig; | |
import javax.servlet.ServletException; | |
import javax.servlet.ServletRequest; | |
import javax.servlet.ServletResponse; | |
import javax.servlet.annotation.WebFilter; | |
@WebFilter(filterName = "CharacterEncodingFilter", urlPatterns = {"/*"}) | |
public class CharacterEncodingFilter implements Filter { | |
@Override | |
public void init(FilterConfig filterConfig) throws ServletException { | |
// NOOP | |
} | |
@Override | |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | |
if (request.getCharacterEncoding() == null) { | |
request.setCharacterEncoding("UTF-8"); | |
} | |
chain.doFilter(request, response); | |
} | |
@Override | |
public void destroy() { | |
// NOOP | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment