[jsp]代码库
package com.gtxy.dynaActionForm.web.filter;
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.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 以 UTF-8 输入输出
*
* @author ZhongHuiQiang
*
*/
public class FilterChar implements Filter {
private String config;
public void destroy() {
this.config = null;
}
/**
* name="FilterChar" <br>
* init-param name="config" value="utf-8"<br>
* mapping url-pattern="/*"<br>
*/
public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req;
req = (HttpServletRequest) request;
HttpServletResponse res;
res = (HttpServletResponse) response;
req.setCharacterEncoding (config);
res.setCharacterEncoding (config);
chain.doFilter (req, res);
}
/**
* 获得web.xml中初始化的参数
*/
public void init (FilterConfig config) throws ServletException {
this.config = config.getInitParameter ("chars");
}
}
------------------------------
<filter>
<filter-name>FilterChar</filter-name>
<filter-class>
com.gtxy.dynaActionForm.web.filter.FilterChar
</filter-class>
<init-param>
<param-name>chars</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>FilterChar</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
初级程序员
by: 东软菜菜鸟 发表于:2013-05-10 12:00:07 顶(0) | 踩(0) 回复
好像没用..
回复评论