码迷,mamicode.com
首页 > Web开发 > 详细

jsp的url后跟中文参数传参出现乱码

时间:2014-06-08 19:49:40      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:des   c   class   code   java   a   

①重新编码:String urlParam= request.getParameter("urlParam");
  urlParam= new String(urlParam.getBytes("ISO-8859-1"), "UTF-8");

②tomcat中统一编码

tomcat  的server.xml中在相对应的端口中加下面两句
useBodyEncodingForURI="true" 
URIEncoding="UTF-8"

在web.xml文件中配一个过滤器:(没有试验成功)

第一步:<filter>
<filter-name>filter</filter-name>
<filter-class>com.social.filter.CodeFilter</filter-class> 设置过滤器的类名(filter包下的CoderFilter类)
</filter>
<filter-mapping>
<filter-name>filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

第二步:编写com.social.filter.CodeFilter类:

import javax.servlet.Filter;

public class CodeFilter implements Filter {

public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// TODO Auto-generated method stub
//把ServletRequest强制转化为HttpServletRequest
HttpServletRequest request=(HttpServletRequest)arg0;
HttpServletResponse response=(HttpServletResponse)arg1;
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
arg2.doFilter(request, response);
}

public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}

 

jsp的url后跟中文参数传参出现乱码,布布扣,bubuko.com

jsp的url后跟中文参数传参出现乱码

标签:des   c   class   code   java   a   

原文地址:http://www.cnblogs.com/zhaochunhua/p/3776101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!