java web中解决乱码的几种方法

来源:互联网 发布:淘宝上的柠檬好吗 编辑:程序博客网 时间:2024/05/21 12:43

1. 接受参数时进行编码转换 String str = new String(request.getParameter("something").getBytes("ISO-8859-1"),"utf-8") ; 2.在请求页面上开始处,执行请求的编码代码 request.setCharacterEncoding("UTF-8") 3.为了避免每页都要写request.setCharacterEncoding("UTF-8"),建议使用过滤器对所有jsp进行编码处理。4.
Response.sendDerect(“/a.jsp?name=URLEncode.encode(“速速”,”utf-8”);5.返回: response.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");相当于在前台页面写<%@ page contentType="text/html;charset=UTF-8" %>  6.response.setLocale(new java.util.Locale("zh","CN")) 



原创粉丝点击