Skip to content

Instantly share code, notes, and snippets.

@froop
Created January 12, 2012 06:35
Show Gist options
  • Save froop/1599078 to your computer and use it in GitHub Desktop.
Save froop/1599078 to your computer and use it in GitHub Desktop.
[Java][Servlet] HTTP-POSTのRequestにsetCharacterEncodingするFilter
public class CharacterEncodingFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) request;
if ("POST".equalsIgnoreCase(httpReq.getMethod())) {
request.setCharacterEncoding("Windows-31J");
}
chain.doFilter(request, response);
}
}
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>sample.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/sample/*</url-pattern>
</filter-mapping>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment