這裡是一個具體的例子
現在因為浏覽器對UTF
以我們使用的tomcat
在編輯JSP頁面時
SetCharacterEncodingFilter的這個類主要的作用就是
在web
Set Character Encoding
org
encoding
UTF
Set Character Encoding
/*
在上面這段文字中
同時注意二個問題
附
package org
import java
import javax
import javax
import javax
import javax
import javax
import javax
import javax
public class SetCharacterEncodingFilter 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
* is null
*/
protected FilterConfig filterConfig = null;
/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;
/**
* Take this filter out of service
*/
public void destroy()
{
this
this
}
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request
FilterChain chain)
throws IOException
{
// Conditionally select and set the character encoding to be used
if (ignore || (request
{
String encoding = selectEncoding(request);
if (encoding != null)
request
}
// Pass control on to the next filter
chain
}
/**
* Place this filter into service
*
* @param filterConfig The filter configuration object
*
*encoding
* UTF
*
*/
public void init(FilterConfig filterConfig) throws ServletException
{
this
this
String value = filterConfig
if (value == null)
this
else if (value
this
else if (value
this
else
this
}
/**
* Select an appropriate character encoding to be used
* characteristics of the current request and/or filter initialization
* parameters
* null
*
* The default implementation unconditionally returns the value configured
* by the encoding initialization parameter for this
* filter
*
* @param request The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request)
{
return (this
}
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19699.html