Take care of JSP technology in minutes

Source: Internet
Author: User

I.the syntax of a JSP
1. Template elements
HTML content written in a JSP
in the translated servlet, the output is directly out.write

2.JSP Script Expressions
format: <%=%>
In the translated servlet, the value of the computed expression is output as-is

3.JSP Script Fragment
format: <% Several Java statements%>
in the translated servlet, copy and paste directly to the corresponding location to execute

variables between multiple fragments can be accessed from each other
the Java code in a fragment can be incomplete, but in the translated servlet, the Java code of multiple fragments must be fully compliant with the Java syntax
cannot include other JSP elements in a fragment

~~4.jsp Statement
The content written in the JSP declaration becomes a member of the class in the same way as the method in the class

5.JSP Comments
<%--Comment Content--%>
content that is commented on by JSP is discarded during JSP translation
Instructions for 6.JSP
(1) Page directive
<% @page Several attribute declarations ...%>
session= "True", default to True, indicating that the translated Servlet will create a session object
If you don't want to create a session, you can change to false

Import Guide Package

pageencoding Specifies which encoding the JSP parsing engine uses to translate the JSP

(2) include directive
<% @include file= "/xxx"%>
The implementation request contains an effect that is statically contained

(3) taglib Directive
used to import TLD files

two. The nine implicit objects of JSP

object representing the JSP runtime environment
(1) The entry object, which can be used to get the other eight implicit objects

GetPage () method ----------------Returns the page implicit object
getrequest () method -------------Returns the request implicit object
GetResponse () Method------------Return response Implicit object
Getservletconfig () method -------return config implicit object
Getservletcontext () method ------Return application Implicit object
getsession () method -------------Returns the session implicit object
getexception () method -----------Return exception implicit object
Getout Method ()-----------------Returns an out implicit object

(2) is itself a domain object and provides a portal to manipulate the other three domain objects

SetAttribute (String name, Object value);
SetAttribute (String name, Object value, int scope);
getattribute (String name);
getattribute (String name, int Scope);
removeattribute (String name);
removeattribute (String name, int Scope);

getattributenames ();

Findattribute ()///In order to find the specified name attribute in the four fields from small to large, return null if not found

(3) provides a convenient way to implement request inclusion and forwarding
pagecontext.forward ("xxx");
pagecontext.include ("xxx");

three. JSP Tag Technology
1.JSP label (provided by Sun Company)

can only get cannot traverse and set
(when used in development, if the expression has a value, the value is displayed directly in the location, and if there is no value, a null is shown directly)

(1) data acquisition
get constant/variable-->${"AAA"} ...
gets the data in the array-->${username} ...-it automatically looks for the corresponding value and outputs it. This El expression is implemented at the bottom level using the Findattribute () method.
get data from Map-->${attr[0]} ...
gets the data in the collection-->${List[0]} ...
gets the data in JavaBean-->${map.key},${map["key"]}...--> need to obtain which property value is not determined by the JavaBean internally defined by the property name, but is determined by the get and set method name. 。 The get or set of the method name and the parentheses after the method are stripped and the first letter lowercase is the name of the property that is required when it is obtained through an El expression.

Note: The variable/collection/array/map/javabean must be placed in the domain before it can be obtained by El

(2) performing operations
Arithmetic Run
the + number can only be used as an operator in El, not as a concatenation character

Logical Operations

Relational Operations

Three -dimensional expression

Empty Operation
returns true for NULL, otherwise false
(3) Get the common development object
            !!! PageContext: The only way to get a value from a domain object directly in an El expression

            !!! Pagescope: Represents the PageContext domain
            !!! Requestscope: Represents the request domain
            !!! Sessionscope: Delegate Session field
            !!! Applicationscope: Represents the ServletContext domain

            !!! Param: A Map collection representing all the parameters, which can be obtained by key acquisition; Map<string, String>
Paramvalues: Represents the acquisition of multiple values for a key; Map<string, string[]>

Header: A Map representing the request header; map<string, string>
headervalues:map<string, string[]>

            !!! Cookie: A Map that represents cookie information; map<string, cookie>

            Note: A cookie object is obtained by means of a cookie, which requires further use of the cookie name to obtain the specified cookie value ${Cookie.username.value}//Get the username value in the cookie

1 2       New Cookies ("Cook", "222"); 3       // Pagecontext.setattribute ("C", c); 4       Response.addcookie (c); 5 %>6   The value of the cookie is: ${cookie.cook.value}

Initparam: A Map representing all Web application initialization information; map<string, string>
3.JSTL Tag Library:
Guide Library: <%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%> prefix: set abbreviation C

<c:out value= "<string>" default= "<string>" escapexml= "<true|false>"/>

  !!! <c:set var= "<string>" value= "<string>" target= "<string>" property= "<string>" scope= "< String> "/>

  !!! <c:if test= "<boolean>" var= "<string>" scope= "<string>" >
...//True to execute

!!! <c:foreach  
items= "<object>"
begin= "<int>"
end= "<int>"
step= "<int>"
var= "<string>"
varstatus= "<string>"

  Bottom encapsulates the For,while,do-while loop in Java.

 The Varstatus property in Foreeach:

  !!! <c:choose><c:when><c:otherwise>

Take care of JSP technology in minutes

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.