Create a filter for duplicate content to make the code cleaner! !! !!
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("Before filtering");
chain.doFilter(request, response);
System.out.println("After filtering");
}
public void init(FilterConfig filterconfig) {}
public void destory() {
}
}
Recommended Posts