标签:mamicode const rate nts throw 内容 chain import web
过滤器的使用:
未用过滤器前,出现乱码:
使用后恢复正常:
过滤器相关代码:
package MyFilter; 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 EncodingFilter */ @WebFilter("/EncodingFilter") public class myFilter implements Filter { /** * Default constructor. */ public myFilter() { // 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 { // TODO Auto-generated method stub // place your code here // pass the request along the filter chain request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); chain.doFilter(request, response); } /** * @see Filter#init(FilterConfig) */ public void init(FilterConfig fConfig) throws ServletException { // TODO Auto-generated method stub } } Filter.java
链接:https://pan.baidu.com/s/1od29C86bFzfnXb3j9acnFA
提取码:uzqx
复制这段内容后打开百度网盘手机App,操作更方便哦
标签:mamicode const rate nts throw 内容 chain import web
原文地址:https://www.cnblogs.com/fengjianbk/p/10741923.html