本教程操作环境:windows7系统、javascript1.8.5版、dell g3电脑。
1.对象 request response 对象setcharacterencoding=utf-8
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8" %> <% //解决post/get 请求中文乱码的方法 request.setcharacterencoding("utf-8"); response.setcharacterencoding("utf-8"); %><!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><title>代码段标签</title></head><body><%! int name; int password; %> <% string name=request.getparameter("username"); string password =request.getparameter("pwd"); out.println("hello "+name+" success! "+"<br/>"); out.println("密码泄露 "+password); %></body>
2. 方法二 (比较简单)
找到tomcat 配置文件 server.xml ,加入code:uriencoding="utf-8"
<connector port="8080" protocol="http/1.1" connectiontimeout="20000" uriencoding="utf-8" redirectport="8443" /><!-- uriencoding="utf-8" 解决get/post 请求 中文乱码 -->
【推荐学习:javascript高级教程】
以上就是javascript中string乱码怎么办的详细内容。
