<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Operation Result:
two printing 99 multiplication table (1) using a JSP expression to print a 99-multiplication table
Results:
(2) using JSP script to print 99 multiplication table
Results:
(3) Comparison of two methods Using the "result+=" output is a string, + = avoids the problem of type conversion and runs faster.
The first is the use of Java has a return value of the method, which is obtained by printmultitable () The return value of string type, directly is a whole 99 times
The contents of the legal table.
The second is the use of Java with parameter no return value method, the added parameter is an object of the JspWriter class, using this in the Printmultitable () method
Object Out Method println (); In the For statement, step through the 99 multiplication table output, relative to the cost of the second method (using memory) a little bit!
Three legacy issues (1) since can <%%> why also have <%!%> <%! %> is specifically used for declarations, which are equivalent to global variable usage and can be found anywhere.
<%! %> can only write variable declarations, <%%> any Java script can write.
<%! %> is placed in the member variable (outside the method), <%%> is placed inside the method (local variable).
<%%>, the next <%%> can be referenced, as long as the order is right, the following can call the above <%%>.
(2) about coding Pageencoding is the encoding of the JSP file itself; ContentType's charset refers to the content encoding when the server is sent to the client.
JSP to pass two times "coding", the first stage will use Pageencoding, the second stage will use utf- 8 to UTF-8, the third stage is the Tomcat
Out of the page, with the ContentType.
The first stage is that the JSP is compiled into. Java, which reads the JSP according to the pageencoding setting, and the result is translated by the specified encoding scheme into a unified utf-
8 Java source code (ie. java), if the pageencoding set wrong, or not set, out of the Chinese garbled.
The second stage is compiled by Javac Java Source to Java bytecode, no matter what coding scheme is used when JSP is written, after this order
The results of the paragraph are all UTF-8 encoding Java source code.
Javac uses UTF-8 's encoding to read Java source code, compiled into a UTF-8 encoding binary (ie. class), which is the JVM to the constant number
A specification that is expressed within a binary code (Java encoding).
The third stage is the Java binary Code of Tomcat (or its application container) loading and executing phase two, and the result of the output is
is seen on the client, this time hidden in phase one and phase two of the parameters ContentType play a role.
Pageencoding is the encoding of the JSP file itself.
ContentType CharSet refers to the content encoding when the server is sent to the client. ContentType are more commonly used.
A follow-up will be devoted to the JSP character encoding.
Java Web Learning (8): Stage Small Project exercise