您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

javascript中string乱码怎么办

2024/3/11 5:00:34发布57次查看
解决方法为:1、找到request和response对象,添加“setcharacterencoding=utf-8”即可;2、找到tomcat配置文件server.xml,添加“uriencoding=utf-8”即可。
本教程操作环境: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乱码怎么办的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product