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

What to do if string is garbled in javascript

醉折花枝作酒筹
Release: 2021-07-20 10:52:49
Original
2587 people have browsed it

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>
Copy after login

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 请求 中文乱码 -->
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template