728x90

Filter

이클립스 new에서 Filter 항목 클릭하면 자동생성됨

인코딩 코드 추가: request.setCharacterEncoding("UTF-8");

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

		request.setCharacterEncoding("UTF-8");
		
		chain.doFilter(request, response);
	}

 

추가로 필터는 Annotation이 @WebFilter이다

 

Exception

1) 클래스생성

2) 클래스 기본생성자 생성

public MemberException() {}

3) 예외처리해줄 메소드 생성 + super()

	public MemberException(String msg) {
			super (msg);
	}

 

 

Filter

package common;

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;

/**
 * Servlet Filter implementation class CommonFilter
 */
@WebFilter("/CommonFilter")
public class CommonFilter implements Filter {

    /**
     * Default constructor. 
     */
    public CommonFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	
	
	
	
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

		request.setCharacterEncoding("UTF-8");
		
		chain.doFilter(request, response);
	}

	
	
	
	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}

 

 

 

Exception

package member.model.vo;

public class MemberException extends Exception {
	public MemberException() {}
	public MemberException(String msg) {
			super (msg);
	}
}

 

728x90
반응형

+ Recent posts