javascript中string乱码怎么办插图

本教程操作环境: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乱码怎么办的详细内容,更多请关注亿码酷站其它相关文章!



javascript中string乱码怎么办
—–文章转载自PHP中文网如有侵权请联系ymkuzhan@126.com删除

云服务器推荐