首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

急浏览器传中文

2011-12-22 
急!浏览器传中文.在线等各位大侠小弟做了一网站,平台是采用jdk1.6+tomcat6.0+mysql5.0在采用浏览器传中文

急!浏览器传中文.在线等
各位大侠;
    小弟做了一网站,平台是采用jdk1.6+tomcat6.0+mysql5.0   在采用浏览器传中文时一切正常,但是在tomcat5.5或resin3.1就出现乱码了.请问这个怎么解决.

a.jsp
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   pageEncoding= "gb2312 "   errorPage= " "   %>
<%@   page     import= "java.io.* "   %>
<%@   page     import= "java.sql.* "%>
<%@   page   import= "java.lang.* "%>
<%@   page   import= "java.util.* "   %>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<link   href= "../style/style1.css "   rel= "stylesheet "   type= "text/css ">
</head>
<body>
<%
request.setCharacterEncoding( "gb2312 ");
out.println( " <script   language= 'javascript '> self.location.href= 'b.jsp?table=foodstuffs&&kinds= "+java.net.URLEncoder.encode( "礼品类 ")+ "&&menus= "+java.net.URLEncoder.encode( " <a   href= 'foodstuffs.htm '> 副食 </a> ")+ " '; </script> ");
%>
</body>
</html>


b.jsp
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   pageEncoding= "gb2312 "   errorPage= " "   %>
<%@   page     import= "java.io.* "   %>
<%@   page     import= "java.sql.* "%>
<%@   page   import= "java.lang.* "%>
<%@   page   import= "java.util.* "   %>
<%@   page   import= "java.net.* "   %>
<%@   page   import= "java.util.Vector "   %>
<%@   page   import= "java.util.Date "   %>
<jsp:useBean   id= "connbean "   scope= "page "   class= "beans.driver1 "/> //这个是一接连数据库beans
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<link   href= "../style/style1.css "   rel= "stylesheet "   type= "text/css ">
</head>
<body>
<%
request.setCharacterEncoding( "gb2312 ");
String   table=   new   String(request.getParameter( "table ").getBytes( "ISO8859_1 "));
String   kinds=   new   String(request.getParameter( "kinds ").getBytes( "ISO8859_1 "));
String   menus=   new   String(request.getParameter( "menus ").getBytes( "ISO8859_1 "));
%>
</body>
</html>

请问我那里写错了,

[解决办法]


你的数据是在URL传递的,到jsp页面时URL已经解析完成了,所以request.setCharacterEncoding( "gb2312 ");不起作用。使用什么编码解析在tomcat中是可以配置的,我不记得是在哪里配了,你自己找找吧。
建议用form提交数据,就不会有这样的问题了。

你的写法很奇怪
既然
request.setCharacterEncoding( "gb2312 ");
干吗还要
String table= new String(request.getParameter( "table ").getBytes( "ISO8859_1 "));
两个都起作用的话肯定乱码

热点排行