预览一-没加过滤器
预览二-加过滤器
项目目录
项目在 Servlet登录二 基础上进行 转码过滤器 扩展
public class EncodingFilter implements Filter { private String characterEncding; private boolean enabled; @Override public void destroy() { // TODO Auto-generated method stub characterEncding=null; } @Override public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { // TODO Auto-generated method stub if(enabled||characterEncding!=null) { arg0.setCharacterEncoding(characterEncding); arg1.setCharacterEncoding(characterEncding); } arg2.doFilter(arg0, arg1); } @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub characterEncding=filterConfig.getInitParameter("characterEncding"); enabled="true".equalsIgnoreCase(filterConfig.getInitParameter("enabled").trim()); } }EncodingFilter.java
<filter> <filter-name>characterEncdingFilter</filter-name> <filter-class>com.yuanze.filter.EncodingFilter</filter-class> <init-param> <param-name>characterEncding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>enabled</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncdingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>Web.xml过滤器配置
链接:https://pan.baidu.com/s/1BOTi3q__sG5oP4Dh-YK4iw
提取码:8pzr