JSP basic syntax

Source: Internet
Author: User

1. Why is there a JSP specification

After the advent of servlet technology, the most troublesome thing to do when using it is to use a large number of out.print statements to output the page. Such a form in the system changes, maintenance, preview the effect is not convenient and quick to complete the task, so the introduction of JSP technology, used to extract the statements in the servlet is responsible for the display

Java code in a 2.JSP page

The Java code in the JSP page contains the following three types of

JSP expressions

JSP Small Script

JSP declaration

Write location

Any location on the page

Role

Control the generation of variable content in the page

3.JSP-expression

Grammar rules: <%= ...%>

Legal content: variable, variable plus operator combination expression, method with return value

Rules translated into servlets: Output the value of the variable, expression, method in the service () method with the Out.print statement

4.JSP Small Script

Grammar rules: <% ...%>

Legitimate content: Java code snippets that can be written in a method are available as small scripts

Rules transferred to servlet: A piece of code inside the Service () method of the Servlet class intact

5.JSP Declaration

Grammar rules: <% ...%>

Legitimate content: Declaration of member properties or member methods

Rules when translating into Servlets: a member property or member method in a servlet class that is translated into a JSP page

Instructions in the 6.JSP page

Syntax rules: <%@ directive Name attribute = value%>

Common directives:

Page directive

Include directives

TAGLIB directive

Role

Controls what the JSP generates when it translates into a servlet class

7.page instruction

Function: For guide package, set page properties

For example:

<%--Guide Pack--%>

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

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

<%--sets the parameter value of the Response.setcontenttype () method--%>

<% @page contenttype= "Image/gif"%>

<%--sets the encoding of the container when it reads the file--

<% @page pageencoding= "UTF-8"%>

8.include instruction

Function: When a JSP page is converted to a servlet, it is possible to include other files in it. You can include a JSP file or a static HTML file.

This statement can be easily included in each JSP page navigation bar, copyright notice, logo, etc.

Grammar:

<% @include file= "url"%>

For example:

<% @include file= "header.html"%>

<% @include file= "footer.html"%>

Hidden objects in a 9.JSP page

What is an implied object

Containers are created automatically, objects that can be used directly in the JSP file

Role:

These pre-created objects in the JSP can simplify access to HTTP requests, response information

Request:httpservletrequest Request Information

Response HttpServletResponse Response Information

Data stream for out JspWriter output

Session HttpSession Sessions

Application ServletContext Global Context Object

PageContext PageContext JSP Page context

Page Object JSP pages themselves

Config servletconfig servlet Configuration object

Exception Throwable Capture Exception page

JSP basic syntax

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.