`
hmx1388
  • 浏览: 36296 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
社区版块
存档分类
最新评论

JSP中文乱码问题

    博客分类:
  • JSP
阅读更多
今天遇到中文乱码问题,与以下网友提问类似,收藏起来,以免下次遇到时使用。
<%@ page contentType="text/html;charset=gb2312" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.sql.*" %>
<html>
   <head> 
    <title> 错误 </title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </head>

   <body>
<% 
String errmsg = null;
String temp = request.getParameter("errmsg");
try
{
errmsg = new String(temp.getBytes("ISO8859-1"),"GB2312");
}
catch(Exception e)
{
 System.out.println(e);
}
out.println(errmsg);
%>     
<font color="red"><c:out value="${param.errmsg}"/>
<a href="addproducts.jsp">返回</a></font> 
   </body>
</html>

参数errmsg是从别的页面传递过来的参数,他的值是一串中文字符.在此页面对errmsg进行显示时全部变成??????了.我已经照以前贴子的方法进行尝试,什么都用上了,还是不行啊.请问还有没有别的方法解决?

试试以下方法可以解决:1)
打开tomcat的server.xml文件,找到区块,加入如下一行:
URIEncoding="GBK"
完整的应如下:
<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/>

2)重启tomcat。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics