Boost智慧指標——weak_ptr
阿新 • • 發佈:2020-08-28
1.導包
javax.servlet
2.編寫過濾器
package com.yl.filter;
import javax.servlet.*;
import java.io.IOException;
public class CharacterEncodingFilter implements Filter {
//伺服器開啟的時候初始化
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("初始化");
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=UTF-8");
System.out.println("CharacterEncodingFilter執行前");
chain.doFilter(request,response);//讓請求繼續走,如果不寫,程式進行到這裡就會停止
System.out.println("CharacterEncodingFilter執行後");
}
//伺服器關閉的時候銷燬
public void destroy() {
System.out.println("已銷燬");
}
}