JSP basic Syntax (ii)

Source: Internet
Author: User

1.Page instruction

Format: <% @page property = "Content"%>

Common directives:

Import : The JSP page requires an imported package, can be repeated multiple times, the other properties can only appear once;

iserrorpage: You can set true or false to indicate whether the page is an error processing page, true indicates that the page specified by ErrorPage can not jump to this page for error handling, and false will not be processed;

ErrorPage: Define this page error when the display page to jump, such as errorpage= "error.jsp", to be used with the Iserrorpage attribute;

pageencoding:jsp page character encoding, the default is iso-8859-1, if there is a Chinese can be set to GBK;

ContentType: Defines the encoding of the JSP character and the MIME type of the page response, or contenttype= "text/html if Chinese is used; CHARSET=GBK ";

MIME: Setting the Application type for open files

The MIME type is set incorrectly, and it is possible to have the download prompt pop-up box, and you can specify the name of the download file:

<%

  Response.setheader ("Content-disposition", "Attachment", Filename= "Test.doc");

%>

For example: *.jsp page: (front)

<%@ page language= "java" import= "java.util.*" contenttype= "text/html; Charset=iso-8859-1 "pageencoding=" UTF-8 "%>

2.*.htm and *.html are exactly the same, with the MIME class being processed, you can view the Tomcat Web. XML configuration

<mime-mapping>
<extension>htm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>HTML</extension>
<mime-type>text/html</mime-type>
</mime-mapping>

3.pageencoding refers to the JSP file itself encoding,contenttype charset refers to the server sent to the client's content encoding;

4. Settings for error pages

Error-prone JSP page:<%@ page iserrorpage= "error.jsp"%><!--the page to jump once an error occurs--

Error JSP page processing:<%@ page iserrorpage= "true"%><!--expression page can handle error--

The jump on the error page belongs to the server-side jump.

server-side Jump : The page content display has changed, but the address bar has not changed. Throughout the process, the client sends only one request to the server side, and the server responds only once to the client page.

client Jump : After the program jumps, the address bar has changed.

You can modify the Web. xml file under Project Web-info and configure the error jump page, such as:

<error-page>
<error-code>404</error-code>
<location>/error/error.jsp</location>
</error-page>

<error-page>
<error-code>500</error-code>
<location>/error/error.jsp</location>
</error-page>

<error-page>
<error-code>java.lang.NullPointerException</error-code>
<location>/error/error.jsp</location>
</error-page>

Sometimes the error page jump page does not appear, it may be that the Tomcat page error.jsp error, so that cannot jump, at this time, you can add the following statement on the error.jsp page:

<% Response.setstatus (200); %>

200: Indicates that the page has no errors and can be displayed normally.

JSP basic Syntax (ii)

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.