JSP/Servlet 인코딩 형식 설정 문제

 Java Web             , JSP/Servlet         ,              request   response       。  ,         JSP/Servlet,   JSP/Servlet    request   response                     ,           request   response              。
                 

            CharacterEncodingFilter

    	
    package org.zeroup.filter;
     
    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 CharacterEncodingFilter implements Filter {
     
        protected FilterConfig filterConfig = null;
        protected String encoding = "";
     
        public void init(FilterConfig filterConfig) throws ServletException {
            this.filterConfig = filterConfig;
            this.encoding = filterConfig.getInitParameter("encoding");
        }
        public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain chain) throws IOException, ServletException {
     
            request.setCharacterEncoding(this.encoding);
            response.setCharacterEncoding(this.encoding);
            response.setContentType("text/html;charset="+this.encoding);
     
            chain.doFilter(request, response);
        }
        public void destroy() {
            this.encoding = null;
            this.filterConfig = null;
        }
    }
           web.xml           

    	
        <filter>
            <description>CharacterEncodingFilter</description>
            <display-name>CharacterEncodingFilter</display-name>
            <filter-name>CharacterEncodingFilter</filter-name>
            <filter-class>
                org.zeroup.filter.CharacterEncodingFilter
            </filter-class>
            <init-param>
    <param-name>encoding</param-name>
    <param-value>utf-8</param-value>
            </init-param>
        </filter>
     
        <filter-mapping>
            <filter-name>CharacterEncodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

          request response             utf-8,                        utf-8。

좋은 웹페이지 즐겨찾기