How is the coding in the java.net.URLEncoder.encode method determined?

in java.net.URLEncoder The

public static String encode (String s, String enc) method, where the enc (character encoding name) determines which character set to use?
after encoding according to the relevant character set, how can I send it to IE,IE to know which character set to use for decoding?

May.23,2022

its function is to convert the character s you enter into the byte [] of the enc encoding format (utf-8 is recommended in jdk) and then convert the corresponding URL encoding characters
the browser itself can parse these URL codes
clipboard.png


1. Confirm what encoding format your WEB container will choose. Take Tomcat as an example, modify the conf/server.xml file under tomcat, as follows:

    <Connector port="8080" useBodyEncodingForURI="true" protocol="HTTP/1.1"
        URIEncoding="UTF-8"
        protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />

2. Confirm which encoding format your front-end page chooses

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Menu