Introduction to JSP syntax

Source: Internet
Author: User
Tags include resource valid client
Elements in the js| syntax JSP page

One, release: Three kinds of annotation,<!----> will print to the client, the remaining two are ignored by the JSP engine.

Second, the template element: refers to the JSP static HTLM or the XML content, it affects the page structure and the esthetic degree, but that is the art thing, has nothing to do with the programmer.

Third, script elements: including declarations (declaration), Expressions (Expression) and scriptlets, except for some minor differences, scriptlets can completely replace the first two functions.

Four, Directive element:

A JSP instruction is a message that the JSP sends to the JSP package container. They are used to set global values, such as class declarations, methods to implement, output content types, and so on, without producing any output to the client's mouth. It only affects this JSP file.

1, age directive: a property used to define and manipulate many important pages, which communicate with the JSP containment. Anywhere in the JSP, a page can contain any number of page directives in any order. But except for the import directive, other directives can only appear once. Several important page directives:

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

<% @ buffer= ""%>//defines a buffer model for the customer output stream.

<% @ info= ""%>//can get the string using Servlet.getservletinfo ()

<% @ iserrorpage= ""%>

<% @ errorpage= ""%>

<% @ isthreadsafe= ""%>//jsp file can be used multiple threads

2, include instructions: ASP used a lot of it, and then introduced.

3, taglib directive: see the author's previous article "The Custom tag in struts".

Five, action elements

The JSP action element is written in XML syntax and works in the request processing phase, which affects the behavior of the JSP runtime and the response sent to the customer. They should be provided by all the containment, regardless of their implementation.

In effect, a standard action is a tag that can be embedded into a JSP page. When a page is compiled as a servlet, when the package container encounters the tag, it replaces it with the Java code for the predefined task that is requested.

1,&LT;JSP:PARAM&GT: Provides additional information for other labels.

<jsp:param name= "paramname" value= "Paramvalue"/>

It is used in conjunction with <jsp:include>,<jsp:forward>,<jsp:plugin>.

2,<jsp:include>

If the containing is a static file, then 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 the implementation of JSP compiler equipment.

Theoretically <% @ Page include= ""%> differs from <jsp:include>, I call it automatic refresh, but when it comes to a higher version of Tomcat, they function the same.

The following is a sample code for this tag:

<%@ page contenttype= "text/html; charset=gb2312 "Language=" Java%>


<body>

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

<%//just included the file in%>

<a href= "two.jsp" >goto two--></a><br>

This examples show include works

<jsp:include page= "two.jsp" flush= "true" >

<jsp:param name= "A1" Value= <%=request.getparameter ("name")%> "/>"

<jsp:param name= "A2" value= <%=request.getparameter ("password")%> "/>"

</jsp:include>

</body>


ßthis is static.html>


<body>

<form method=post action= "jsp_include.jsp" >

<table>

<tr>

<td>please Input your name:</td></tr>

<tr><td>

<input Type=text name=name>

</td></tr>

<tr><td>input you password:</td>

<td>

<input Type=text name=password>

</td>

</tr>

<tr>

<td>

<input Type=submit value=login>

</td>

</tr>

</table>

</body>


ßthis is a two.jsp-->

<%@ page contenttype= "text/html; charset=gb2312 "Language=" Java%>

Give an example of how include works:

<br>

This is A1=<%=request.getparameter ("A1")%>

<br>

This is A2=<%=request.getparameter ("A2")%>

<br>

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

3,<jsp:forward> is allowed to forward requests to another jsp,servlet, or to a static resource file. This action is especially useful when you want to convert to a different view based on a different request. However, the resource to which the request is diverted must be in the same context as the JSP send request.

<jsp:forward page= "url" >

<jsp:param name= "paramname" value= "Paramvalue"/>

</jsp:forward>

4,<jsp:usebean> it to instantiate the JavaBean, or to locate an existing bean instance and assign it to a variable name (or ID). and a specific scope is given to determine the life cycle of the object.

<jsp:usebean id= "myclassname" scope= "page" class= "Class1" type= "Class2"/>

Equivalent to: Class2 myclassname=new Class1 ();

Page: Represents an object associated with a specific request to the page.

Request: Represents an object that is associated with a specific customer request to the page. If a request is sent to another JSP using a <jsp:forward> standard action, or if a <jsp:include> action contains another JSP, the object is valid in the JSP involved.

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

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

5,<jsp:setproperty> and <jsp:getProperty>

Work with Usebean to set the bean's simple properties and indexed properties, because it's used too often, so let's not say a little bit, you learn in concrete code.

<jsp:serproperty name= "Beanname" bopertydetails/>

A, property=*;

B,property= "PropertyName" param= "ParameterName"

Use this method when the property name in the bean differs from the parameter name in the request.

C,property= "PropertyName"

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

D,property= "PropertyName" value= "PropertyValue"

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.