Syntax: ========================================================================================================== 1. <% =%> Expression operation, the value after the = number can only be String Type 2 Put the class, function, variable declaration in <%!%> 3. Note <% -%> <% - -%>
Server built-in static object: ==================================== 1. Out.println (String) and System.out.Println (String) : Out.println inherits from javax.servlet.jsp.jspwriter class, direct output for client web content system.out.println (String) is the output of the server Java system console 2. To be in multiple The share variable (transfer parameters) in the JSP page, use the Request object SetAttribute and GetAttribute. 3. The data type bonded in the session and Application objects can only be Java objects: String, Integer, Vector, etc. Can't be a normal data type, such as int, double, float, etc.
Character encoding: ==========================
This time is a Japanese character encoding problem: (Chinese character encoding problem can also be found in the following)
First, clear static and dynamic Japanese characters
The static Japanese characters are not in the JSP statement <%%>, <%!%>, Etc., the dynamic Japanese characters are opposite.
Problem Description:
All static Japanese characters in the JSP page have become similar / U5117 / U6125 ... characters after output to the client.
The problem is most likely to appear in the following steps: First, the JSP page will first convert to the Java intermediate file, this step needs to be restocked, then the Java intermediate file is compiled as a Class file, you need to make characters re-coded. Above Two steps are related to the character encoding set supported by the current JVM system. My machine is a Windows2000 Chinese operating system, and there is no installation of Japanese characters in the control panel> zone settings. This may be the problem. The JVM of the operating system does not support Shift_JIS Japanese character set encoding, the Japanese string encoded without the Japanese character set. By default, the dynamic Japanese character removed from the database, which is directly output to the page without the conversion of Java and Class, and the display is the correct Japanese character.
Solve: Japanese is MBCS (multibly character set coding), that is, there may be two byte combinations in a string, or there may be a byte character, and must pass the internal code conversion, see the internal code conversion below. Function, use this function to re-coding Japanese, and finally output to the client, you can display Japanese correctly.
String trans (string str) {string strresult = null; byte tmp []; try {tmp = str.getbytes (); strresult = new string (tmp, "shift_jis");} catch (exception e) {system.out. PRINTLN (E.GetMessage ());} Return strRRRESULT;} In fact, it is only necessary to use this conversion function to re-encode the last output of Unicode code to Shift_JIS Japanese characters, and finally output, for example, Write like this: <% = trans ("Japanese characters")%>
Talking about JSP page coding problems (as an example, Chinese can be referred to): 1. <@Page ContentType = "text / html; charset = shift_jis"> This sentence is only indicating the browser: the character set of the current page is Shift_JIS Japanese code, that is, the client's page source code is explained by Japanese code.
2. <% Request.setCharacterencoding ("Shift_JIS");%> This sentence indicates that the request parameter value accepted by the JSP page needs to be re-encoded as a SHIFT_JIS Japanese format.
3. What is the conversion function is required to convert the encoded function? Only when the character output to the client page is not a Japanese code, the conversion function is used. <% = trans ("Japanese characters")%>