본문 바로가기

프로그래밍/JSP

필터 - 캐릭터 인코딩

CharacterEncodingFilter.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
 
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;
 
//모든 jsp파일에 적용
@WebFilter("/.jsp")
public class CharacterEncodingFilter implements Filter {
 
    private String encoding;
    
    public CharacterEncodingFilter() {
        // TODO Auto-generated constructor stub
    }
 
    
    public void destroy() {
        // TODO Auto-generated method stub
    }
 
    
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        
        request.setCharacterEncoding(encoding);
        chain.doFilter(request, response);
    }
 
    public void init(FilterConfig Config) throws ServletException {
        // TODO Auto-generated method stub
        encoding = Config.getInitParameter("encoding");
        if (encoding == null) {
        encoding = "UTF-8";
        }
    }
 
}
 
cs


'프로그래밍 > JSP' 카테고리의 다른 글

JDBC - JDBC란?  (0) 2018.07.21
JDBC - JDBC 프로그래밍 예제(1)  (0) 2018.07.21
파일 업로드  (0) 2018.07.20
MVC 패턴 구현  (0) 2018.07.19
필터 - 로그인 검사 필터  (0) 2018.07.19