JSP syntax introduction

xiaoxiao2021-03-06  64

Elements in the JSP page

I. Release: Three annotations, will print to the client, and the remaining two are ignored by the JSP engine.

Second, template element: refers to the static HTLM or XML content in the JSP, which affects the structure of the page and theesthetics, but that is a business, it is unrelated to programmers.

Third, scripting elements: including declaration, expression (Expression), and scriptlets, in addition to some minor differences, ScriptleTs can replace the first two functions.

Fourth, instruction elements:

The JSP instruction is a message sent by the JSP to the JSP package container. They are used to set the full game, such as class declarations, the way to implement, and output content types, etc., and do not generate any output to the customer. It only affects this JSP file.

1. AGE instruction: Used to define and operate the properties of many important pages, these properties communicate with the JSP package container. Anywhere in JSP, in any order, one page can contain any number of PAGE instructions. However, in addition to the Import instruction, other instructions can only appear once. Several important PAGE instructions:

<% @ Page import = "java.io. *, Java.util. *"%> // Import package

<% @ Buffer = ""%> // Defines the buffer model for the customer output stream.

<% @ Info = ""%> // You can use servlet.getServletInfo () to get this string

<% @ IserrorPage = ""%>

<% @ Errorpage = ""%>

<% @ ISthreadsafe = ""%> // can use multiple threaded use

2, include instructions: there are a lot of ASP, and later introduce.

3, Taglib Directive: For details, please refer to the author Previous article "Custom Tag in Struts".

Five, action elements

The JSP action element is written in XML syntax, which is a response to the JSP runtime, and the response is sent to the customer in the requesting phase. They should be provided by all bag containers regardless of their implementation.

From the effect, a standard action is a tag that can be embedded in the JSP page. During the page is compiled as a servlet, when the package container encounters this tag, it is replaced with the Java code corresponding to the requesting predefined task.

1, : Provide additional information for other tags.

It is used with , , .

2,

If included is a static file, just add the content to the JSP file, this file will not be executed by the JSP compiler, if it is a dynamic file, will be executed by the JSP compilation equipment.

Theoretical <% @ Page Include = ""%> Differences with , I called it automatic refresh, but actually uses higher version of Tomcat, their function is the same.

Here is sample code for this mark:

<% @ Page ContentType = "text / html; charset = GB2312" Language = "java"%>

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

<% // just put the files in%>

Goto Two ->

This Examples show include Works

" />

" />

ßthis is static.html>

please input your name:

Input You Password:

ßthis is a two.jsp ->

<% @ page contenttype = "text / html; charset = GB2312" Language = "java"%>

For example, the principle of incrude work:


This is a1 = <% = Request.getParameter ("A1")%>


This is A2 = <% = Request.getParameter ("A2")%>


<% out.println ("Hello from Two.jsp");%>

3, is allowed to forward requests to another JSP, servlet, or static resource file. This action is particularly useful when converting to different views according to different requests. However, the resource requested to be steered must be located in the same context environment as the JSP send request.

4, It is used to instantiate JavaBean, or locate an existing Bean instance and assign it to a variable name (or ID). And give a specific range to determine the life cycle of the object.

Equivalent: Class2 myclassname = new class1 ();

Page: Indicates that the object is associated with a specific request to the page.

Request: Indicates that the object is associated with a particular customer request to the page. If the request is sent to the standard action to the other JSP, or use the actions that contain additional JSP, the object is valid in the JSP involved.

Session: In the current session, this object is valid in any request sent by the same customer.

Application: In the same Web application, this object is valid in any JSP page.

5, &

Collaborate with UseBean to set the simple properties and index properties of Bean, because it is too frequent, then I will tell you less, everyone learns in specific code.

A, Property = *;

B, Property = "PropertyName" param = "parametername"

This method is used when the attribute name in the bean is different from the parameter name in the request.

C, Property = "PropertyName"

The properties in the bean must be the same as the parameter name in the request.

D, Property = "PropertyName" value = "PropertyValue"

转载请注明原文地址:https://www.9cbs.com/read-112179.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.039, SQL: 9