Java Web Note: The page instruction in JSP, jsppage

Source: Internet
Author: User

Java Web Note: The page instruction in JSP, jsppage

The page command is an important attribute in jsp. You can use this attribute to define the relevant attributes of a jsp page, including the MIME type, package to be imported, error page designation, and so on.

Common page commands have the following attributes:



For the preceding commands, only the import command can be repeated, and only one other command can appear.


Setting the MIMEcontentType attribute of a page is the most commonly used attribute. To display Chinese characters on a jsp page, you must specify MIME encoding for the whole page. MIME: multipurpose internet mail extensions, multi-function Internet mail extended service, is a description of the program to open a file with an extension. The general setting command is: <% @ page language = "java" contentType = "text/html; charset = GBK" %> Note: If the contentType above is omitted, however, garbled characters may occur in earlier versions of tomcat, so it is best to write it.
Open with word: <% @ page language = "java" contentType = "application/msword; charset = GBK" %>


In addition to charset, you can use pageEncoding to specify the file encoding. <% @ Page language = "java" contentType = "text/html; pageEncoding = GBK" %>
PageEncoding sets the encoding of the jsp file, while the charset server in contentType sends the content encoding to the client. If pageEncoding exists, the jsp encoding is determined by pageEncoding; if it does not exist, it is determined by the charset in contentType, and if none exist, it uses the default ISO-8859-1 encoding method.

If you want to jump to the specified page to display the error information after an error occurs on the page, you must first specify the page to jump to when the error occurs and set it through the errorPage attribute; the error handling page must be clearly marked and specified through the isErrorPage attribute. Their relationships are as follows:

Instance: show page:
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% @ page errorPage =" error. jsp "%> <% int result = 100/0; // an error occurs here. The error page is displayed. %>


Error Page:
<% @ Page language = "java" contentType = "text/html; charset = GBK "pageEncoding =" GBK "%> <% @ page isErrorPage =" true "%> <body> 

Result:

The above jump is a server jump. Because the address bar has not changed, the client only sends one request to the server during the entire operation, and the server only responds to the client once; if the address bar changes, it is equivalent to a jump in the form of a hyperlink, This is the client jump.
At the same time, you can specify global error handling in the entire virtual directory. By modifying the web. xml file, you can add an error page to the file.
Database Connection operations use import in the page command to import the packages required for development, and import the java. SQL package to perform database development operations.
<% @ Page contentType = "text/html" pageEncoding = "GBK" %> <% @ page import = "java. SQL. * "%> 













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.