-
view plaincopy to clipboardprint?
1,页面上编码设置为"UTF-8"
2,写一个字符编码过滤器, 在web.xml中配置加载过滤器
3,设置tomcat的属性 在配置端口的节点上加入如下代码:URIEncoding="UTF-8"
1,代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2,实现代码:
package com.mww.comm;
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;
public class checkEcodingFelter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest servletrequest,
ServletResponse servletresponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletrequest;
HttpServletResponse response = (HttpServletResponse) servletresponse;
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
filterChain.doFilter(servletrequest, servletresponse);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
在web.xml中配置过滤器:
<!-- 字符编码过滤 -->
<filter>
<filter-name>checkEcodingFelter </filter-name>
<filter-class>com.mww.comm.checkEcodingFelter </filter-class> <!-- 配置过滤器类 包名+类名 -->
</filter>
<filter-mapping>
<filter-name>checkEcodingFelter </filter-name>
<url-pattern>/* </url-pattern> <!-- 过滤所有页面-->
</filter-mapping>
3,在tomcat配置端口的节点上配置该属性URIEncoding="UTF-8" :
<Connector port="8888" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
按这一套下来乱码问题解
相关视频
相关阅读 ie6下面asp.net mvc3 部署应用程序在asp.net mvc中实现右键菜单和简单的分页教程ASP.NET中MVC框架模式方法如何实现分享ASP.NET 2.0 中保护机密数据ASP.NET配置文件Web.configASP.NET 2.0 AJAX中Webservice调用方法ASP.NET 的安全认证实现ASP.NET生成随机密码功能
热门文章 没有查询到任何记录。
最新文章
Java中Servlet获得异步
Java中Servlet获得异步支持java递归实现文件的删除和拷贝innerHTML怎样失焦判断FreeMarker和Jsp的应用范围
人气排行 java如何远程登录linux并执行其命令教你用jsp写反弹的shellFreeMarker和Jsp的应用范围Java 7关于#的用法jsp统计在线人数代码Java短信发送机的实现如何用java连接数据库方法Java中Servlet获得异步支持
查看所有0条评论>>