Jsp, el, jstl-front-end interview
I had no idea what I learned in the past. Today I have a glimpse of it.
Jsp is used to display all data that can be operated on. <%>
Attribute in el operation scope cannot operate on local variables $ {}
Jstl is used to use tags instead of <%> statements containing if loops in jsp.
1. jsp
Jsp is a java servlet page. Like servlet, jsp is a technology defined by sun for developing dynamic web pages. Java code can be embedded in the page to provide dynamic data for users.
Jsp is actually a servlet, which is translated from the container into the servlet Source file and then compiled. You can see the servlet response results.
Nine built-in jsp objects
| Built-in object |
Content |
Scope |
| Request |
Request |
Request |
| Response |
Response to the request |
Page |
| Out |
Used to send text data to the client |
Page |
| Session |
Creates a session object for the requested client. |
Session |
| Application |
Obtain the servlet context from the servlet configuration object |
Application |
| PageContext |
Contains all the information on this page |
Page |
| Config |
ServletConfig of this jsp |
Page |
| Page |
Instance that processes the current request class on this page |
Page |
| Exception |
Indicates the exception during running. |
Page |
The scope of the action in the third column of the table above, that is, the scope of the built-in object, as the name suggests, is "within the scope of the effective ". The four scopes are: page --- request --- session --- application:
Page -- valid on the current page
Request -- valid in the current request
Session -- valid in the current session
Application -- valid in all applications
-----------------------------------------------------------
2. EL expression
Introduction: The full name of EL is Expression Language. EL Expressions generally operate on attributes in application, session, request, and pageContext. EL variables refer to attributes in a certain scope.
Note: el expressions cannot operate on local variables!
Usage:
Use the EL expression to obtain the data Syntax: "$ {identifier }"
When an EL expression statement is executed, pageContext is called. the findAttribute method uses the identifier as the keyword to search for the corresponding object from the four domains of page, request, session, and application. If it is found, the corresponding object is returned. If it is not found, the corresponding object is returned. "(note, is not null, but a null String ).
Example: $ {user}
EL expressions can also easily obtain attributes of JavaBean or data of arrays, collections, and Map types. For example:
$ {User. address. city}
$ {User. list [0]}: access an element at a certain position in an ordered set
$ {Map. key}: obtains the value of the specified key in the map set.
Obtain common web development objects
1. pageContext: indicates the pageContext object, for example, $ {pageContext. name1}
2. pagination: indicates the page domain.
3. requestScope: indicates the request domain.
4. sessionScope
5. applicationScoope
6. param: Map object. All request parameters are saved.
7. paramValues: Map object (value corresponds to an array ).
8. header: Map object. Obtain the value of a request header. Note: If the header contains "-", for example, Accept-Encoding, headerValues ["Accept-Encoding"] is required.
9. headerValues: Map object (value corresponds to an array)
10. cookie: Map object. (Value corresponds to a cookie object)
11. initParam: Map object. (Key = parameter name value = parameter value, which is configured in web. xml) for example $ {initParam. encode}
-----------------------------------------------------------
3. JSTL
JSP Standard Tag Library, JSP Standard Tag Library, core Tag Library: http://java.sun.com/jsp/jstl/core contains the common work of Web applications, such as: loop, expression assignment, basic input and output.
Reference <% @ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
Common labels are as follows:
Used to display data examples in JSP:
Store the value in the scope or assign a value to the variable attribute in the JavaBean instance:
Delete a variable that exists in the scope:
Conditional Control labels: And Usage is the same as if () else {}
Loop Control label:
URL tags:
Contains another JSP page to this page. But it has a wide range of functions, including not only resources under the project, but also external resources!
Used for page redirection
Used to include passing Parameters