JSP - filter 필터 &한글처리

by 조쉬 posted Mar 28, 2021
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

 

 

 

 

 
 
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
package config;
 
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;
 
//filter 선처리 클래스
//아래 요청에 대해서 모든 필터를 적용해라
//filter와 url 맵핑
@WebFilter("/*")
public class EncodingFilter implements Filter {
 
    private String charset = "utf-8";
    
    //서버가 중지 될때 작동
    public void destroy() {
 
        System.out.println("필터 종료");
    }
 
    // 요청이 들어왔을때 거쳐가는 코드
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
 
        // 선처리할 코드
        request.setCharacterEncoding(charset);
 
        chain.doFilter(request, response);
    }
 
    // 웹서버가 실행될때 자동으로필터를 초기화 시킴
    public void init(FilterConfig fConfig) throws ServletException {
 
        System.out.println("필터가 초기화 되었습니다.");
 
    }
 
}
 
cs