jsp-02-using JSP for output

Source: Internet
Author: User
Tags html comment tld

Second, the use of JSP to achieve output

JSP page composition: Static content, instructions, expressions, scriptlet, declarations, actions, annotations

JSP scripts: Expressions, scriptlet, declarations

Expression: <%= content%>

Scriptlet: <% Java code%>

Disclaimer: <%! Java variables, methods%>

JSP directives: page, include, taglib

2.1 Use page to specify Settings page properties
    1. Set the character set pageencoding
    2. Set Language language
    3. Importing package Import
    4. Specify buffer size (Kbytes) buffer
    5. Specifies the URL of the error handling page ErrorPage
    6. Whether the page is an error handling page Iserrorpage
    7. 7. whether to ignore the calculation of the EL expression iselignored

The character set of the newly created JSP page is iso-8859-1, and the Chinese character cannot be saved at this time.

<%@ page language="java" contenttype="text/html; Charset=iso-8859-1 "


Saving kanji requires the use of utf-8 characters. You can reset the new file to be utf-8.

2.2 Include directives

The runtime embeds an HTML file or JSP page into another JSP page.

<%@ include file= "file name"%> executes fast and executes directly with the original file

<jsp:include page= "File" flush= "Ture" > Encounters this line in edit, returning the result.

2.3 taglib directive

Introduce the Tag library profile (TLD) into the page and set the prefix to use the label's tag in the tag library description file. The tag descriptor file is in XML format and contains a series of label descriptions whose file suffix is. tld.

<%@ taglib url= "tag Library descriptor file" prefix= "prefix name" >

2.4 Out for page output

<% out.println ("My JSP page"); %>

<% Out.print ("My second webpage"); %>

Output effect:

To view the source file:

2.5 notes

The comments in the JSP are divided into three types:

    1. 1. HTML annotations

<!--HTML comments--

    1. 2. JSP annotations

<%--JSP comments--

    1. 3. JSP Script Comments


/* Multiline Comment */

Single-line Comment


The difference between the three is: HTML comment is not secure




2.6 JSP declaration and use variables

1. <%%> Local Variables

2. <%! %> all variables and methods

3. Escape characters:

1) Single quote ' changed to '

2) Double quotation mark "instead of"

3) slash \ Change to \ \

4) Start tag <% change to &lt;%

5) end tag%> change to%\> or%&gt;

2.7 JPS expression for page output

<% Out.print (); %>


Note: When you need to import additional packages in an expression, use the page directive, where multiple packages are written together, separated by commas (,).

2.8 JSP Execution principle

The generated Java files and class files are saved in the project path in work

1) Client Request

2) The Web container translates the JSP page into the source code of the servlet. Java

3) The source code generated by the Web container is compiled . Class

4) The Web container loads the compiled code and executes

5) respond to the results of the execution to the client

2.9 Common Web Program errors

1) 404 cannot find a page or resource to access

Possible causes: URL input error at run time

Place the page under Web-inf

External boot tomcat, project not deployed

2) JSP page code error

Possible error: JSP page code has errors

jsp-02-using JSP for output

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.