Home  >  Article  >  Java  >  Java web page garbled solution

Java web page garbled solution

尚
Original
2019-11-23 10:00:271892browse

Java web page garbled solution

Common places where java web pages are garbled are as follows:

In the jsp page. EL expressions or direct values, even if you write a fixed Chinese display, it will be messy.

java code. The value transmitted from front end to back end is garbled.

jsp page encoding.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

Anyone who writes jsp is familiar with changing the character set of the page.

java background code.

If it is a java web project, you can set the encoding format when obtaining values ​​in post and get methods.

POST method

request.setCharacterEncoding("utf-8");

GET method

request.setCharacterEncoding("utf-8");
//例如获取页面的username值进行转换
String username =new String(request.getParameter("username").getBytes("iso8859-1"),"utf-8");

For more java knowledge, please pay attention to java basic tutorial.

The above is the detailed content of Java web page garbled solution. 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