Coding, coding of the problem

    It goes without saying coding for important programs, if not completely understand coding, in many places it will haunt you.

    An obsession with coding, there's just learning jsp when the garbage problem up to now more than a year, has been fuzzy state, now, do not know is not really completely understand, but there is little harvest, after thoroughly looking forward to understand, in this first record it bit by bit.

   From the beginning of garbled.

   Tells the browser first is the jsp in the garbage, First set the encoding of the jsp in place, pageEncoding in the page tag is encoding for the jsp compiled into a servlet taken in the contentType setting in the web server responds to the browser when encoding response header, taken, so that the browser can correctly interpret html file, setCharacterEncoding in response is also a web server tells the browser, encoding files taken, of which there is a priority, reponse> contentType, and in html meta tags are also used to respond to the browser encoding device is provided in the jsp is preferentially disposed in the meta html coding method.

   Setting solve the problem, then understand the principles of which is the transmission of information first B / S structure is binary to pass, because we passed a string, which would put strings into a binary response, we know that, in the different encoding methods, to give the corresponding binary information are different, encoding a variety of ways, ISO-8859-1, uNICODE, UTF-8, gbk, available in Chinese unicode manner, utf-8, gbk but the general use gbk, gbk is because special created for Chinese characters, not to say the other is not good, but unicode is focused on the world of platform development, and utf-8 is a byte variable length to a string that represents, although utf-8 represents the Chinese character is very good, but after all, is the Chinese official gbk do, in fact, better use utf-8, if the Chinese characters include English characters, is also recommended.

   General procedures for using the content editor has a corresponding encoding, for example, in the edit jsp myeclipse default is to use the edit iso-8859-1, and the default is to use ANSI Notepad editing (of course also be saved by to set the encoding is), the browser is also written in the program, it also has encoding of the response. After the coding is decoded to solve the problem, because different coding problem, the same binary information will have a good variety of different forms corresponding to the coded character set, so before you know coding, in order to pass the correct decoding mode decoding display the correct characters, here only discuss the use of jsp web developer, so just use express encoding, other similar, we must first show that the process, first by sending the address, URL in the course of the browser and server interaction in different the browser uses a different URL encode, the Chinese browser commonly used gbk, and if modified encoding the browser is also possible, in the interior of use is http protocol that requires information passed four parts a request line, two request header, three wrap is the end of the header information, four parameter information request, the request line included in the corresponding commit mode, then the address is submitted, then the version of the protocol, and the request header information including a browser, such as a browser class can identify MIME , Browser version, etc., is the last parameter information requests, get requests if used the way, the information submitted is represented by a key-value pair in the back of the URL, if the POST request is used in the last part of parameter information place. Reach the server is, web servers will take corresponding coding scheme to decode information to tomcat, for example, if the time of submission of URL, get this is by default iso-8859-1 encoding, if containing non iso-8859-1 characters will appear garbled, the solution there, connector writes URIEncoding = "coded character set" in the server.xml tomcat in the document Use useBodyRequestForURI = true, where the difference between the first information corresponding to the request in the get url all web servers are used to encode the coding provided, which is re-encoded (decoded information within each request ), just one page, rather than the corresponding first way to encode all pages, but also to take advantage of this new String (request.getParameter ( ""). getBytes ( "iso-8859-1"), "encoding"); re-write. If using post submission, it will only be set at the first read parameter information about the coding mode can be (request.setCharacterEncoding ( '')); if tired of each request must be written on request.setCharac. can be set by the filter when you can ...

Guess you like

Origin blog.csdn.net/soliy/article/details/5325464