LoginSignup
0
0

More than 3 years have passed since last update.

【Java】フィルターを作成

Posted at

重複する内容はフィルターを作成してスッキリとしたコードに!!!

EncodingFilter.java
package tool;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;

@WebFilter(urlPatterns = { "/*" })
public class EncodingFilter implements Filter {
    public void doFilter(
        ServletRequest request,
        ServletResponse response,
        FilterChain chain
    ) throws IOException, ServletException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");

        System.out.println("フィルター処理前");

        chain.doFilter(request, response);

        System.out.println("フィルター処理後");

    }

    public void init(FilterConfig filterconfig) {}

    public void destory() {
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0