- jwfpd
- 等级: 初级会员

- 性别:
 - 文章: 21
- 积分: 30
- 来自: 中国安徽

|
java 代码
java中文处理:
一,在tomcat的server.xml文件中加入
java 代码
- <Connector
- ="8080" maxHttpHeaderSize="8192"
- maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
- enableLookups="false" redirectPort="8443" acceptCount="100"
- connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/>
URIEncoding="GBK"部分
二,做一个过滤器:
java 代码
- package weijin.com.bbs.system.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;
-
- public class EncodingFilter implements Filter
- {
-
- String defaultEncoding = "utf8";
-
- public void init(FilterConfig config) throws ServletException
- {
- String encoding = config.getInitParameter("encoding");
- if (encoding != null)
- {
- defaultEncoding = encoding;
- }
- }
-
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
- {
- request.setCharacterEncoding(defaultEncoding);
- chain.doFilter(request, response);
- }
-
- public void destroy()
- {
- defaultEncoding = null;
- }
-
-
- }
三:在web.xml中配置:
java 代码
- <filter>
- <filter-name>Encoding</filter-name>
- <filter-class>weijin.com.bbs.system.filter.EncodingFilter</filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- </filter>
-
- <filter-mapping>
- <filter-name>Encoding</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
<filter-name></filter-name>
OK,完成!
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- kyo100900
- 等级:


- 性别:
 - 文章: 173
- 积分: 620
- 来自: 北京

|
URIEncoding="GBK"部分
String defaultEncoding = "utf8"
为什么两次编码不一致?
|
返回顶楼 |
|
|