?? encodingfilter.java
字號:
package com.laoer.comm.web;
import javax.servlet.http.HttpServlet;
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.FilterChain;
import javax.servlet.http.*;
import java.io.IOException;
/**
* <p>Title: 天乙軟件工作室公共包</p>
* <p>Description: 天乙軟件工作室公共包</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: 天乙軟件工作室[LAOER.COM/TIANYISOFT.NET]</p>
* @author 龔天乙(Laoer)
* @version 1.0
*/
public class EncodingFilter
extends HttpServlet
implements Filter {
private FilterConfig filterConfig;
private String targetEncoding = "ASCII";
/**
* Called by the web container to indicate to a filter that it is being placed
* into service.
*
* @param filterConfig FilterConfig
* @throws ServletException
* @todo Implement this javax.servlet.Filter method
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.targetEncoding = filterConfig.getInitParameter("encoding");
}
/**
* The <code>doFilter</code> method of the Filter is called by the container
* each time a request/response pair is passed through the chain due to a
* client request for a resource at the end of the chain.
*
* @param request ServletRequest
* @param response ServletResponse
* @param chain FilterChain
* @throws IOException
* @throws ServletException
* @todo Implement this javax.servlet.Filter method
*/
public void doFilter(ServletRequest srequest, ServletResponse sresponse,
FilterChain chain) throws IOException, ServletException {
try {
HttpServletRequest request = (HttpServletRequest) srequest;
request.setCharacterEncoding(targetEncoding);
chain.doFilter(srequest, sresponse);
}
catch (ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
catch (IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}
/**
* Called by the web container to indicate to a filter that it is being taken
* out of service.
*
* @todo Implement this javax.servlet.Filter method
*/
public void destroy() {
filterConfig = null;
targetEncoding = null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -