⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 characterencodingfilter.java

📁 本公司开发项目中本人做的公共类文件。如文件的操作
💻 JAVA
字号:
package com.intohotel.util;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterEncodingFilter implements Filter {
	  /**
	  * The default character encoding to set for requests that pass through
	  * this filter.
	  */
	  protected String encoding = null;

	  /**
	  * The filter configuration object we are associated with. If this value
	  * is null, this filter instance is not currently configured.
	  */
	  protected FilterConfig filterConfig = null;

	  /**
	  * Should a character encoding specified by the client be ignored?
	  */
	  protected boolean ignore = true;

	  public void init(FilterConfig filterConfig) throws javax.servlet.ServletException {
	    this.filterConfig = filterConfig;
	    this.encoding = filterConfig.getInitParameter("encoding");
	    String value = filterConfig.getInitParameter("ignore");
	    if (value == null)
	      this.ignore = true;
	    else if (value.equalsIgnoreCase("true"))
	      this.ignore = true;
	    else if (value.equalsIgnoreCase("yes"))
	      this.ignore = true;
	    else
	      this.ignore = false;

	  }
	  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException {
	    // Conditionally select and set the character encoding to be used
	    if (request.getCharacterEncoding() == null) {
	      String encoding2 = selectEncoding(request);
	      if (encoding2 != null)
	        request.setCharacterEncoding(encoding2);
	    }

	    // Pass control on to the next filter
	    chain.doFilter(request, response);
	  }
	  public void destroy() {
	    this.encoding = null;
	    this.filterConfig = null;
	  }

	  protected String selectEncoding(ServletRequest request) {

	  return (this.encoding);

	  }

	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -