软件下载
文件大小:
软件介绍
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"/>
按这一套下来乱码问题解
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"/>
按这一套下来乱码问题解
发表评论(共0条评论)
版权声明:
1 本站所有资源(含游戏)均是软件作者、开发商投稿,任何涉及商业盈利目的均不得使用,否则产生的一切后果将由您自己承担!
2 本站将不对任何资源负法律责任,所有资源请在下载后24小时内删除。
3 若有关在线投稿、无法下载等问题,请与本站客服人员联系。
4 如侵犯了您的版权、商标等,请立刻联系我们并具体说明情况后,本站将尽快处理删除,联系QQ:2499894784
点击加载更多评论>>