code063.java
package pack01;
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;
//�ַ��������������
public class code063 implements Filter
{
String encoding = null;
@Override
public void destroy()
{
this.encoding = null;
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
if (encoding != null)
{
request.setCharacterEncoding(encoding);
response.setContentType("text/html; charset=" + encoding);
}
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
encoding = filterConfig.getInitParameter("encodingx1");
}
/*
* ����tomcat��������web.xml�ļ������ô���
*<filter>
* <filter-name>code063</filter-name>
* <filter-class>pack01.code063</filter-class>
* <init-param>
* <param-name>encodingx1</param-name>
* <param-value>UTF-8</param-value>
* </init-param>
*</filter>
*<filter-mapping>
* <filter-name>code063</filter-name>
* <url-pattern>/*</url-pattern>
*</filter-mapping>
*</web-app>
*
*/
}