Detailed explanation of JSP-to-Servlet Conversion

Source: Internet
Author: User

There are two main types of VE ve:
Page, allows you to do something similar to import classes, define servlet Superclass), mso-hansi-font-family: "">, etc;
Include, which allows you to insert a file into the servlet class when the JSP file is translated as a servlet ).

I. JSP page Directive

 
 
  1. <%@ page  
  2. [ language="java" ]  
  3. [ extends="package .class" ]  
  4. [ import="{package .class | .*}, ..." ]  
  5. [ session="true|false" ]  
  6. [ buffer="none|8kb|sizekb" ]  
  7. [ autoFlush="true|false" ]  
  8. [ isThreadSafe="true|false" ]  
  9. [ info="text" ]  
  10. [ errorPage="relativeURL" ]  
  11. [ contentType="mimeType [ ;charset=characterSet ]" |  
  12. "text/html ; charset=ISO-8859-1" ]  
  13. [ isErrorPage="true|false" ]  
  14. %> 

Page directive mso-hansi-font-family: ""> allows you to define case-sensitive attributes:

(1) import = "package. class" or import = "package. class1,..., package. classN ".
Mso-hansi-font-family: "">

You can specify the packages you want to import. For example:

 
 
  1. <%@ page import="java.util.*" %> 

The import attribute is the only one of these attributes that can appear multiple times in a JSP.

(2) contenType = "MIME = Type" or contentType = "MIME-Type; charset = Character-Set" mso-hansi-font-family: "">

It specifies the MIME type of the output. The default value is "text/html ". For example:

 
 
  1. <%@ page contentType="text/plain" %>" 

(3) isThreadSafe = "true | false ". if the value is "true" by default), it means that a common servlet will be processed, and multiple requests will be processed in parallel by one servlet instance. In this case, programmers synchronously Access Multiple instance variables. When the value is "false", the servlet will implement SingleThreadModel in single-thread mode. No matter whether requests are submitted sequentially or concurrently, different separated servlet instances will be provided.

(4) session = "true | false ". If the value is "true" by default) indicates that the predefined variable session inherits HttpSession. It should be bound to an existing session. Otherwise, a session should be created and bound. If the value is "false", the session variable will not be used. If you try to use the variable, an error will occur during JSP conversion to Servlet.

(5) buffer = "sizekb | none ". Determine the buffer size for the JSPWriter output. The default value is determined by the server, but at least 8 KB is required.

(6) autoflush = "true | false ". If the value is "true mso-hansi-font-family:" ">", the system automatically clears the buffer when it is full, if the value is "false mso-hansi-font-family:" ">", an exception is thrown when the buffer is full, which is rarely used. When buffer = "none" is false, the mso-hansi-font-family: ""> value is invalid.

(7) extends = "package. class ". This will generate a superclass for the servlet. Please use this feature with caution, because the server may have defined one.

(8) info = "message ". Defines a string that can be obtained by calling the getServletInfo method.

(9) errorPage = "URL ". Specify a JSP mso-hansi-font-family: ""> page to handle any unexpected error that can be thrown but not processed on the current page.

(10) isErrorPage = "true | false ". Specifies whether the current page can handle errors from another page. The default value is "false ".

(11) language = "java" mso-hansi-font-family: "">. Specify the following language. However, you don't have to worry about this property because "java mso-hansi-font-family:" ">" is both a default and a legal choice.

JSP ctive like JSP include Directive allows you to include a file during JSP conversion to Servlet. Syntax:

 
 
  1. <Jsp: includePage="{RelativeURL | <% = expression %> }" Flush="True"/>
    Mso-hansi-font-family: "; mso-font-kerning: 0pt"> or
  2. <Jsp: includePage="{RelativeURL | <% = expression %> }" Flush="True">
  3. <Jsp: paramName="ParameterName" 
  4. Value="{ParameterValue | <% = expression %> }"/> +
  5. </Jsp: include>

URL mso-hansi-font-family: ""> generally, relative to the JSP page pointing to it ", you can use the slash "/" as the starting URL to inform the system of the main path of the relative Web server URL mso-hansi-font-family: "">. The contained files are parsed in the form of JSP rules. Therefore, you can use static HTML, scripting elements, directives, and actions.

Let's look at an example. Many sites contain a small navigation bar on each page. It usually appears at the top or right of the page and is contained in every page. It is natural to use include directive to implement it. It is a nightmare to copy these statements to every page using the HTML mso-hansi-font-family: ""> rule. See the following code:

 
 
  1. <HTML>
  2. <HEAD>
  3. <TITLE> JSP tutorial </TITLE>
  4. </HEAD>
  5. <BODY>
  6. <% @ IncludeFile="/Navbar.html"%>
  7. <! -Other parts of this page... -->
  8. </BODY>
  9. </HTML>

Because the file is inserted when the page JSP is converted to Servlet, if the navigation bar changes, you need to put all JSP mso-hansi-font-family pointing to it: ""> the page is all re-compiled once. If your navigation bar is not changed frequently, it is undoubtedly efficient to do so. However, if your included files are frequently changed, we recommend that you use JSP: include action later, it only contains files when the page is requested.

  1. Analysis of JSP server
  2. Monitor JVM available memory in JSP
  3. JSP Init and Destory functions improve work efficiency
  4. Basic JSP compiler syntax
  5. Analysis on compiling JSP tags

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.