Home  >  Article  >  Web Front-end  >  What to do if string is garbled in javascript

What to do if string is garbled in javascript

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-20 10:52:492441browse

The solution is: 1. Find the request and response objects and add "setCharacterEncoding=UTF-8"; 2. Find the tomcat configuration file server.xml and add "URIEncoding="utf-8"" Can.

What to do if string is garbled in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

1. Object request response object 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. Method 2 (relatively simple)

Find the tomcat configuration file server.xml and add code:URIEncoding="utf-8"

<Connector port="8080" protocol="HTTP/1.1"
                connectionTimeout="20000"
                URIEncoding="utf-8"               
                redirectPort="8443" />
<!-- URIEncoding="utf-8"  解决get/post 请求 中文乱码 -->

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What to do if string is garbled in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn