JSP Basic Syntax

Source: Internet
Author: User

1 The origin of JSP

Servlet generation, there is a big problem, in order to show the effect of the page, you need to output a large number of HTML statements, expressed as a string, not only conducive to development, but also not conducive to the maintenance of the later, resulting in JSP. It is primarily used to extract the statements that are responsible for display in the servlet. When a JSP file is written out, it will eventually run through the JSP.

2 What is a JSP

is a component specification for a server-side dynamic page technology developed by Sun.

3 syntax

<%  for (int=0< ; I+ +) {       %>

Code blocks, also known as scripts

Shown in the servlet as

Out. Print (3+5); out. Print (add()); Print (Xx.getname ()); Print (Xx.getname ()+"abc"));
<%= 1 + 2 %>

Output statement, expressed as

Out.println (1+2);

Instructions in a JSP page

<%@ instruction name  attribute =%>

Common directives include the following three types of

Page directive

Include directives

TAGLIB directive

The page directive allows you to import the Java package you want to use in your JSP page, or you can set some properties of the page

<%--Guide Pack--%><%@ Page Import="Java.util.*“%><%@ Page Import="Java.util.*, java.sql.*“%><%--sets the parameter value of the Response.setconenttype method--%><%@ Page ContentType=“text/Html;charset=Utf-8“%><%--sets how the container decodes the file when it is read--%><%@ Page pageencoding="UTF-8“%>

The include directive is used primarily to include other pages in another page. Many pages in the same application will have the same navigation head, copyright notice, repeated in each page is not necessary, and if the navigation head changes when it is not conducive to all page updates. If you make such a common part of a file alone, you only need to add a reference to different pages, you can implement page content reuse.

<% file = %>

JSP Implicit Object

Since the JSP page eventually translates into a servlet, and as a previous version of the servlet that is about to be transformed, there are many systems available to the page to use directly, the creation of these objects is done by the system, the object name is also system named, according to the function of the page to be implemented directly to use.

These hidden objects can be used directly in the JSP

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.