为什么返回的是乱码?中文不能正常显示! 前面加上<%@ page contentType="text/html; charset=GB2312"%> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 web服务器是什么?什么版本<%@ page contentType="text/html; charset=GBK"%> 这是表单间传递参数的乱码问题,给你看一下这个二、表单提交中文时出现乱码 下面是一个提交页面(submit.jsp),代码如下: <html> <head> <title>JSP的中文处理</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <form name="form1" method="post" action="process.jsp"> <div align="center"> <input type="text" name="name"> <input type="submit" name="Submit" value="Submit"> </div> </form> </body> </html> 下面是处理页面(process.jsp)代码: <%@ page contentType="text/html; charset=gb2312"%> <html> <head> <title>JSP的中文处理</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <%=request.getParameter("name")%> </body> </html> 如果submit.jsp提交英文字符能正确显示,如果提交中文时就会出现乱码。原因:浏览器默认使用UTF-8编码方式来发送请求,而UTF-8和GB2312编码方式表示字符时不一样,这样就出现了不能识别字符。解决办法:通过request.seCharacterEncoding("gb2312")对请求进行统一编码,就实现了中文的正常显示。修改后的process.jsp代码如下: <%@ page contentType="text/html; charset=gb2312"%> <% request.seCharacterEncoding("gb2312"); %> <html> <head> <title>JSP的中文处理</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <%=request.getParameter("name")%> </body> </html> 我在我的电脑上试了,没有问题,可以正常运行,也没有显示乱码,我用的是Tomcat4.1.不过有点建议,form.html最好改成这样:<html> <head> <title>理解JSP的原理</title> </head> <body> <p>请输入显示的次数:</p> <form method=get action="helloworld.jsp"> <input type="text" name="times"> <input type="submit" value="提交"> </form> </body></html>注:<input type="text" name="times"> <input type="submit" value="提交">这两句中你缺少引号 fengfengjunjun的方法好像不行耶 victorylj谢谢你,我就不懂我的为什么出现乱码!其它的都是 <%@page contentType="text/html; charset=gb2312"%> 页面头加上<%@ page contentType="text/html; charset=GBK"%>要么就是对汉字编码- java用poi操作word问题 java.lang.reflect.InvocationTargetException javabean编译:非法的类型开始,需要标识符? 关于jsp链接数据库的问题 servlet映射问题。大家帮我看看?? common-httpClient提交中文参数值问题!!!急 关于TAG的问题~~~请进 关于servlet的问题 好奇怪的问题: 求翻页类一个 请问如何判断输入的是不是中文?没遇到过这问题,头大 关于jsp显示图片的问题 期盼中
<%@ page contentType="text/html; charset=GBK"%>
下面是一个提交页面(submit.jsp),代码如下:
<html>
<head>
<title>JSP的中文处理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head> <body>
<form name="form1" method="post" action="process.jsp">
<div align="center">
<input type="text" name="name">
<input type="submit" name="Submit" value="Submit">
</div>
</form>
</body>
</html>
下面是处理页面(process.jsp)代码:
<%@ page contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>JSP的中文处理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head> <body>
<%=request.getParameter("name")%>
</body>
</html>
如果submit.jsp提交英文字符能正确显示,如果提交中文时就会出现乱码。原因:浏览器默认使用UTF-8编码方式来发送请求,而UTF-8和GB2312编码方式表示字符时不一样,这样就出现了不能识别字符。解决办法:通过request.seCharacterEncoding("gb2312")对请求进行统一编码,就实现了中文的正常显示。修改后的process.jsp代码如下:
<%@ page contentType="text/html; charset=gb2312"%>
<%
request.seCharacterEncoding("gb2312");
%>
<html>
<head>
<title>JSP的中文处理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head> <body>
<%=request.getParameter("name")%>
</body>
</html>
<html>
<head>
<title>理解JSP的原理</title>
</head>
<body>
<p>请输入显示的次数:</p>
<form method=get action="helloworld.jsp">
<input type="text" name="times">
<input type="submit" value="提交">
</form>
</body>
</html>注:<input type="text" name="times">
<input type="submit" value="提交">
这两句中你缺少引号
<%@ page contentType="text/html; charset=GBK"%>要么就是对汉字编码-