Pre: All the following JSP standard syntaxes have corresponding XML compatibility label representation.
Java code in JSP, the correspondence between JSP and Servlet
1. <% = Java expression %>
Eg: Current Time: <% = new java. util. Date () %>
XML expression: <JSP: expression> JAVA expression </jsp: expression>
In jsp1.2 and later versions, as long as the program designer does not mix XML and standard JSP methods on the same page (<% =... %>), the server is required to support this syntax.
2. <% Java code %>
Eg: <%
String querydata = "";
If () {} else {}
%>
XML expression: <JSP: scriptlet> JAVA code </jsp: scriptlet>
3. <%! Filed or method definition %>
XML expression: <JSP: Declaration> filed or method </jsp: decalration>
4,JSP/servlet correspondence
The _ jspservice method in the servlet class generated by compilation will be added to the above 1 and 2, and this method will always be called by the North service method.
And 3 will program servlet attributes or methods independently.
The JSP compiled servlet in Tomcat can be viewed in the tomdir/work/localhost directory.
JSP page command: controls the structure of the generated Servlet
<% @ Page import = "Java. util. *, java. Logging. *" %>The package that should be imported when JSP is imported into servlet.
<% @ Page contenttype = "mime-type; cahrset = character-set" %>Same as <% response. setcontenttype ("application/vnd. MS-execel"); %>.
The default MIME type for JSP pages is text/html (the default character set is ISO-8859-1)
If you only want to change the character set, you can use <% @ page pageencoding = "shift_jis" %>
<% @ Page session = "true" %> <% -- default -- %>
Whether the property control page participates in an HTTP session.
There are other attributes:
Isellgnored attributes: Ignore (true) JSP 2.0 Expression Language (EL) and perform normal evaluation.
Buffer attributeSpecify the buffer size used by the out variable (type: jspwriter. Buffer actually used by the server> = given value
<% @ Page buffer = "32kb" %> indicates that the data is cached to 32kb. The page is completed or the output is cleared explicitly (for example, response. flushbuffer). Otherwise, the document is not downgraded and sent to the customer. If the buffer zone is disabled, the JSP element with the header or status code needs to appear at the top of the file. If the response time of each sentence output is too long, disabling the buffer zone will make the customer see some results faster. Buffer = "NONE" indicates disabled.
Autoflush attributes: Determines whether to automatically clear the output (true by default) when the buffer is full or throw an exception after overflow. ,
Info attributesThe string obtained by using the getservletinfo method in the servlet.
Erroepage attributesIt is used to specify error pages for specific pages. To create error pages for the entire web or for different types of errors, you need to use the error-page element in Web. xml.
Eg:
Computespeed. JPs:
......
<% @ Page errorpage = "/WEB-INF/speederrors. jsp" %>
......
Speederrors. jsp
......
<% @ Page iserrorpage = "true" %> <% -- default: false -- %>
......
<% = Exception %>
......
<% Exception. printstacktrace (New printwriter (out); %>
......
Isthreadsafe attributes:
The isthreadsafe attribute of JSP: page is the same as the singlethreadmodel interface of servlet. It is not recommended to use it. Explicit synchronization measures should be used.
Extends attribute specifiedThe servlet superclass generated on the JSP page. Generally not used.
Language attributesDevelop the script language used on the page
XML compatibility Syntax of JSP: Page:
<JSP: Directive. directivetype attribute = "value"/>