Jsp syntax and page commands

Source: Internet
Author: User

Create an index in the application. jsp file. The file index_jsp.java and index_jsp.class will be generated under the tomcat work directory, that is, the java statement is embedded in the html language. on the server side, the class file will be generated to use out. write () output. If the code identified by <%> is met, it is directly written to the java file. Generally, data is generated using servlet and displayed in jsp. The data is stored in the request domain, data is transmitted to jsp through forwarding. Because servlet and jsp share a request domain, you can obtain data encapsulated in the request domain in servlet.
Jsp syntax
1. template element: the html content on a jsp page is called a jsp template element. It defines the basic skeleton of a webpage, that is, the structure and appearance of the page.
Ii. jsp script expression: Used to output data to the browser
<%
String data = "hello ";
Out. write (data );
%>
The script expression <% = data %> serves the same purpose as using out. write (data);, and outputs data to the browser. <% = Data %> translated as out. print (data) in the source code );
3. Script fragment: The fragment that embeds multi-line java code
<%
String data = "hello ";
Out. write (data );
%>
Is a script fragment. Only java code can appear in the script fragment, and the java syntax must be followed, when translating jsp pages, the jsp Engine places the content in the fragments in the Servlet's _ jspService method. Data in different script fragments can be shared, the statement of a single script segment can be incomplete, but all the script fragments on the jsp page must be complete.
4. jsp Declaration: the code in the Declaration will be translated outside sevice.
<% Public void run () {}%> is incorrect because this section of code is put into the service method, and other methods cannot be defined in the java method, so it is an incorrect definition method,
<%! Public void run () {}%> is the correct method, which indicates that the method is declared as external service and serves as the java code outside sevice. Declarations allow jsp to have its own methods.

5. jsp comments: <% -- %>
Used in jsp <! --!> The content is not displayed, but the content still exists in the source file of the page, but is hidden by the browser and not displayed, the content between <% -- %> does not exist in the original file of the page.
Vi. jsp commands
1, page: Example: <% @ page contentType = "text/html; charser =" UTF-8 "%>, if a command has multiple attributes, it can be written separately or in a single instruction.
Language = "java"
Extends = "package. class"
Import = "package. class | package. *" available when multiple packages are imported "," Segmentation
Session = "true | false" indicates whether to create a session when translating it into a Servlet. If it is true, it can be directly used in jsp.
Buffer = "none | 8kb | siizekb" indicates whether to use the cache. When cache is used, when the written data is first written to the cache and then written to the browser at one time, the default cache is 8 KB.
AutoFlash = "true | false" indicates whether to automatically refresh when the cache is full.
IsThreadSafe = "true | false". If it is set to false, the SingleThreadModel interface is implemented when it is translated into a servlet, that is, the thread is secure, when a servlet fails to complete the previous user request, a new servlet is created.
Info = "text"
ErrorPage = "relative_url. The setting value of the errorPage attribute must use a relative path. If it starts with"/", it indicates the root directory of the current web application. You can also use global configuration in web. xml.
<Error-page>
<Exception-type> jva. lang. SrithmeticException </exception>
<Location>/error. jsp </location>
<Error-page>

The errorpage in jsp has a higher priority than the configuration in the web. xml file.
IsErrorPage = "true | false". If a page is an error handling page, you can set the isErrorPage attribute of this page to true, in this way, when you jump to the error handling page, the exception object will be passed to the servlet on the error handling page. You can view the cause of the exception in the source code.
ContentType = "text/html; charset = UTF-8" Page type and encoding, http response for the browser to open in what encoding format
PageEncoding = characterSet | ISO-8859-1"
IsEIgnored = "true | false"

 

From sdtarena

Related Article

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.