<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
..
<filter>
<description>
</description>
<display-name>CharsetEncodingFilter</display-name>
<filter-name>CharsetEncodingFilter</filter-name>
<filter-class>filters.CharsetEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharsetEncodingFilter</filter-name>
<url-pattern>/*</url-pattern> <!-- 콘텍스트 제외? -->
</filter-mapping>
..
</web-app>
package filters;
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;
public class CharsetEncodingFilter implements Filter {
public CharsetEncodingFilter() {
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// <
request.setCharacterEncoding("euc-kr");
response.setContentType("text/html;charset=euc-kr");
/*
HttpServletRequest request1 = (HttpServletRequest) request;
String path1 = request1.getContextPath();
String pathinfo = request1.getRequestURI();
String realPath = request.getRealPath(pathinfo);
String url = request1.getServletPath();
HttpSession session = request1.getSession(); */
..
// >
chain.doFilter(request, response);
}
public void init(FilterConfig fConfig) throws ServletException {
}
}