比如我的程序是
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<body>
<%
String str=request.getParameter("number");
double n=Double.parseDouble(str);
%>
<p>传过来的数值是:<br>
<%=n %>
</body>
</html>生成的servlet代码中的中文乱码:String str=request.getParameter("number");
double n=Double.parseDouble(str); out.write("\r\n");
out.write("<p>浼犺繃鏉ョ殑鏁板�鏄�<br>\r\n");
out.print(n );
out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>");
} catch (Throwable t) {
把编码方式换成UTF-8生成的servlet还是中文乱码 ,怎么解决这个问题?
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<body>
<%
String str=request.getParameter("number");
double n=Double.parseDouble(str);
%>
<p>传过来的数值是:<br>
<%=n %>
</body>
</html>生成的servlet代码中的中文乱码:String str=request.getParameter("number");
double n=Double.parseDouble(str); out.write("\r\n");
out.write("<p>浼犺繃鏉ョ殑鏁板�鏄�<br>\r\n");
out.print(n );
out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>");
} catch (Throwable t) {
把编码方式换成UTF-8生成的servlet还是中文乱码 ,怎么解决这个问题?
解决方案 »
- Java好复杂,好多技术和框架
- struts2文件上传的问题
- Servlet问题,求解[急]
- 哪个有officeproject2003能发我邮箱吗
- 关于序列化问题的请教。。。。。。。。。。。。。。。。。。。。。。。。。。
- 急用!!sax解析xml问题,请大家帮忙看看
- 在lomboz中启动tomcat,不能打开http://localhost:8080
- 求Spring in Action 中文版电子书
- 要调用这个servlet,在tomcat5.0中要做那些设置(附代码)?
- Web组件如何获取结果集?
- 新手请教 用JavaBean连接MS SQL 数据库 的代码怎么写 ? 急急急 在线等!!!
- js 写cookie jsp 为什么读不出(在线等)
<html>
<body>
<%
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String str=request.getParameter("number");
double n=Double.parseDouble(str);
%>
<p>传过来的数值是:<br>
<%=n %>
</body>
</html>
试试看
改成和TOMCAT里面的编码一样的格式试下吧 我的理解是:这个JSP代码是通过TOMCAT这个中间件来处理的
不知道对不对啦 你试下啦
况且,这不一定是乱码,
你用UTF-8字符集来看这个文件的么?
好像DW可以的。
保持JSP文档中几个方面的一致就行了:
1。JSP文档自己的文件物理字符集(Eclipse中文件属性中设置),具体到你的情况就是GB2312
2。<head>中的<META http-equiv=Content-Type content="text/html; charset=gb2312">
3。<%@ page contentType="text/html; charset=GB2312" %>