EL and JSTL practice questions

EL and JSTL practice questions

multiple choice

1.
Among the following JSTL tags, which are not flow control tags are ( )

A, A, <c:set>
B, B, <c:choose>
C, C, <c:when>
D, D, <c:if>
reference answer:
A
answer description:
<c:set> tag is used For setting variable values ​​and object properties
2.
Among the following options, the statement about EL expression syntax is correct ().

A、A、 < u s e r n a m e > B 、 B 、 <username> B、B、 <username>BB{username}
C、C、 ( u s e r n a m e ) D 、 D 、 (username) D、D、 ( u ser name ) D D [username]
Reference answer:
B Answer
explanation:
The syntax statement of EL expression starts with "" symbol and ends with " " symbol. The specific format is as follows: {" symbol starts, Ended with "}", the specific format is as follows:Start with " symbol and end with " " symbol, the specific format is as follows: {expression}, the expression must meet the requirements of EL syntax
3.
Read the following code snippet: c_out.jsp: <%–the first out tag-- %> The value of the userName1 attribute is: <c:out value="username1" default="unknown" /> <%–the second out tag--%> The value of the userName2 attribute is: <c:out value="username2 "> unknown </c:out> When using a browser to access c_out.jsp, the page display effect is ()

The value of A, A, userName1 attribute is: unknown The value of userName2 attribute is: username2 The
value of B, B, userName1 attribute is: username1 The value of userName2 attribute is: username2 The value of
C, C, userName1 attribute is: null The value of userName2 attribute Value: null
D, D, value of userName1 attribute: username1 Value of userName2 attribute: unknown
Reference answer:
B
Answer description:
The output text content is the value of the value attribute, and when the value attribute is null, the output default value is
4 ,
The following options are not keywords in EL ()

A, A, and
B, B, or
C, C, not
D, D, no
Reference answer:
D
Answer description:
All keywords in EL: and eq gt true instanceof or ne le false empty not lt ge null div mod
5.
Which of the following statements about the <c:out> tag is wrong ( )

A, A, <c:out> tags are used to output data
B, B, <c:out> tags can implement functions similar to JSP expressions
C, C, and the value attribute of the <c:out> tag specifies the output Data
D, D, and the value attribute of the <c:out> tag cannot be an EL expression
Reference answer:
D
Answer explanation:
The value attribute of the <c:out> tag can be an EL expression
6.
Regarding the implicit object in EL, Which of the following statements is wrong ( ).

A, A, and pageScope can take out the parameters B, B, and request in the smallest domain object PageContext, and
session is a built-in object in El.
There are 11 implicit objects in C, C, and EL. The commonly used ones are pageScope, reuqestScope, and sessionScope. applicationScope
D, D, EL and jstl complement each other and enrich jsp functions.
Reference answer:
B
Answer explanation:
There are 11 implicit objects in EL, commonly used are pageScope, reuqestScope, sessionScope, applicationScope. request and session are built-in objects in JSP
7.
The correct operation result of the EL expression ${(1==2)?3:4} is ( )

A, A, true
B, B, false
C, C, 3
D, D, 4
reference answer:
D
answer description:
judge whether 1 is equal to 2, return 3 if it is equal, return 4 if it is not equal
8,
read the following code snippet: c_if .jsp: <c:if test="${1==1}" > hello world </c:if> The effect when accessing the c_if.jsp in the browser is ( )

A, A, the browser is blank, the console has information display
B, B, the browser reports an error, the console is abnormal
C, C, the browser displays: hello world, the console is normal
D, D, the browser is normal, the console displays : hello world
Reference answer:
C
Answer explanation:
The test attribute is used to set the logical expression, and when the result is true, the content in the tag body should be output
9.
Regarding the EL expression language, which of the following statements is wrong ( )

A, A, variables in EL expressions must be pre-defined before they can be used
B, B, its basic form is ${var}
C, C, EL language can only be used in JSP files, usually in the program code of Servlet class Do not use it
D, D, it can make the code of the JSP file more concise
Reference answer:
A
Answer explanation:
The variable in EL is a basic storage unit, and the variable in EL can be used directly without prior definition. Use EL to obtain the data stored in the domain object
10.
Among the following options, the equivalent EL expression to request.getAttribute("p"); is ()

A、A、 < r e q u e s t . p > B 、 B 、 <request.p> B、B、 <request.p>BB[requestScope.p]
C、C、 ( r e q u e s t . p ) D 、 D 、 (request.p) D、D、 ( re q u es t . p ) D D {requestScope.p}
Reference answer:
D
Answer description:
None
11.
Regarding the operators in EL, which of the following statements is wrong ( )

A, A, "-" operator can be used as minus sign or minus sign
B, B, empty operator is not a prefix operator
C, C, operator (?:) is similar to if-else in Java When statement
D, D, "/" or "div" operators perform division, the quotient is a decimal. Reference
answer:
B
Answer explanation:
In EL, the empty operator can be used to determine whether an object is empty. It is a prefix operator, that is, the empty operator is placed in front of the operand to determine whether an object or variable is null or empty.
12.
Among the following options, the correct way to write the identifier of EL is ()

A, A, 123user"name
B, B, or
C, C, pageContext
D, D, username
Reference answer:
D
Answer explanation:
EL identifiers cannot start with numbers. They cannot be keywords in EL, such as and, or , gt, etc. It cannot be an EL implicit object, such as pageContext. It cannot contain special characters such as single quotation mark ('), double quotation mark ("), minus sign (-) and forward slash (/).
13.
Among the following options, the usage of using coolie to obtain objects is wrong ( ).

A, A, ${cookie.userName}
B, B, ${cookie.userName.name}
C, C, ${cookie.userName.value}
D, D, cookie . user Name . text ∗ ∗ < fontcolor = green > Reference answer: < / font > ∗ ∗ D ∗ ∗ < fontcolor = red > Answer explanation: < / font > ∗ ∗ The usage example of the cookie object is as follows: Get the information of the cookie object: {cookie.userName.text} **< font color=green>Reference answer:</font>** D **<font color=red>Answer explanation:</font>** The usage example of the cookie object is as follows: Obtain the information of the cookie object:cookie.userName.text<font color _ _ _ _ _=green>reference answer:</font>D<font color _ _ _ _ _=red>answer description:</font>The usage example of the coo ki e object is as follows: Get the information of the coo ki e object: {cookie.userName} Get the name of the cookie object:cookie . user Name . name Get the value of the cookie object: {cookie.userName.name} Get the cookie object value of:coo ki e . u ser N am e . nam e obtains the value of coo ki e object: {cookie.userName.value}
14.
There is the following part of code in c_if.jsp: <c:if test="true" > true < /c:if> <c:else test="false" > false </c:else> The correct statement for the above code snippet is ()

A, A, when the page code deployment starts, the console will report an
error B, B, there will be a compilation error on this page, and there will be a red cross prompt
C, C, the result will appear when visiting this page: true false
D, D, visiting When this page is displayed, the browser does not display any information
Reference answer:
C
Answer explanation:
There is no <c:else> tag, and the content in the tag is displayed on page
15.
Regarding the JSTL tag library, which of the following statements is wrong ( )

A, A, JSTL simplifies the development of JSP and Web applications
B, B, JSTL reduces the amount of script code in JSP in a unified way
C, C, JSTL is conditional judgment, iteration, internationalization, database access, etc. Provide support D, D, JSTL is
an important feature of JSP2.0, there is no need to introduce tag libraries when writing JSP pages
. Set of standard tag library (JavaServer Pages Standard Tag Library), referred to as JSTL. Before using these tag libraries, you must use the <%@ taglib%> directive at the top of the JSP page to define the referenced tag library and access prefix. 16. Read the following code snippet: <c:set var="sum" value="0"/> <c:forEach var="i" begin="2" end="10" step="2"> <c :set var="sum" value=" sum + i " / > </ c : for E ach > sum = {sum+i}"/> </c:forEach> sum=




sum+i"/></c:forEach>sum= {sum} The correct statement for the above code snippet is ( )

A, A, output the sum of 1 to 10
B, B, output the sum of odd numbers between 1 and 10
C, C, output the sum of even numbers between 1 and 10
D, D, output 0
reference answer:
C
answer Explanation:
The <c:set> tag is used to set variable values ​​and object attributes, The var attribute of <c:forEach> is used to save the currently iterated element to the name of the page field, and the items attribute is used to specify the items to be iterated Collection object, the begin attribute is used to specify the number of elements in the collection to start to iterate from. The index value of begin starts from 0. If the items attribute is not specified, iterates from the value specified by begin until the end of the iteration. The step attribute is used to specify the step size of the iteration, that is, the increment of the iteration factor.

multiple choice

17.
Among the following options, which are constants in EL are ( )

A, A, true
B, B, 100
C, C, 1.2E4
D, D, null
Reference answer:
A, B, C, D
Answer explanation:
The constants in EL are: Boolean constants true and false, integer constants ( Same as decimal integer constants in Java), floating point constants (floating point constants are represented by the integer part plus the decimal part, and can also be represented in exponential form), string constants, Null constants (represented by null) 18, the
following
options Among them, the implicit objects that pageContext can obtain are ( ).

A, A, applicationScope
B, B, pageScope
C, C, cookie
D, D, header
Reference answer:
A, B, C, D
Answer description:
pageContext can obtain other 10 implicit objects, including pageScope, requestScope, sessionScope, applicationScope, param, paramValues, header, headerValues, cookie, initParam.
19.
Which of the following options are keywords in EL is ()

A, A, eq
B, B, empty
C, C, div
D, D, instanceof
Reference answer:
A, B, C, D
Answer description:
All keywords in EL: and eq gt true instanceof or ne le false empty not lt ge null div mod
20.
Regarding the function of the ${customer.name} expression below, the correct statement is ()

A, A, obtain the customer object
B, B, obtain the name attribute of the customer object
C, C, the obtained customer object must have the getCustomer() method in the four domains
D, D, obtain the name attribute, because there is a corresponding customer object The getName() method
reference answer:
B, D
Answer explanation:
Get the name attribute of the customer object to get the name attribute because there is a corresponding getName() method in the customer object
21,
the following about the dot operator (.) and square bracket operations In the expression of symbol ([ ]), the correct one is ()

A、A、 u s e r [ " M y − N a m e " ] B 、 B 、 {user["My-Name"]} B、B、 user["MyName"]BB{users[0].userName}
C、C、 u s e r [ " M y − N a m e " ] D 、 D 、 {user["My-Name"]} D、D、 user["MyN am e " ] D D {customer.name}
Reference answer:
A,B,D
Answer explanation:
The square bracket operator in EL has the same function as the dot operator, both are used to access certain objects in the JSP page Attributes, when the obtained attribute name contains some special symbols, such as "-" or "?" and other symbols that are not letters or numbers, you can only use the square bracket operator to access the attribute. 22. Among the following implicit
objects
, The method used to obtain the request parameters passed by the client is ()

A, A, param
B, B, paramValues
​​C, C, initParam
D, D, headerValues
​​Reference answer:
A, B
Answer description:
In JSP pages, it is often necessary to obtain the request parameters passed by the client. For this, EL provides Param and paramValues ​​are two implicit objects, these two implicit objects are specially used to obtain the request parameters passed by the client when accessing the JSP page.
23.
Among the following options, the implicit object used to access the scope is ().

A, A, pageScope
B, B, requestScope
C, C, sessionScope
D, D, applicationScope
Reference answer:
A, B, C, D
Answer description:
4 implicit objects for accessing scope are provided in EL , namely pageScope, requestScope, sessionScope and applicationScope.

True or False

24.
The four implicit objects of pageScope, requestScope, sessionScope and applicationScope can store attributes through the setAttribute() method, and obtain attributes through the getAttribute() method


Reference
answer:
Explanation for
the answer:
None
25.
EL expressions start with the symbol " " and end with the symbol " ". The specific format starts with the symbol {" and ends with the symbol "}". The specific format is" symbol and end with " " symbol, the specific format is {expression}.


Reference
answer:
Explanation for
the answer:
None
26.
initParam is an implicit object used to obtain the initialization information of the Web application.



Reference answer:
Explanation for
the answer:
No
27.
The <c:out> tag is used to output the result of expression calculation to the JSP page.



Reference answer:
Explanation to
the answer:
No
28.
The implicit objects in EL expressions and the implicit objects in JSP are shared by them except the pageContext object, and other implicit objects are irrelevant.


Reference
answer:
Explanation to
the answer:
None
29.
The initParam implicit object of the EL expression can obtain the Servlet information configured in the web.xml file.


Reference
answer:
Wrong
answer description:
The initParam object is used to obtain the value of the initialization parameter of the Web application.
30.
The conditional operator in the EL expression is used to perform a certain conditional judgment, which is similar to the if-else statement in the Java language.


Reference
answer:
Explanation for
the answer:
None
31.
The two operators provided by EL expressions for accessing data are . and [], both of which have exactly the same effect.


Reference
answer:
Incorrect
answer explanation:
When the attribute name to be accessed contains some special characters, such as . or ? and other symbols that are not letters or numbers, [] must be used. If you want to get a value dynamically, you can use [] to do it, but it is impossible to get a value dynamically.
32.
The uri attribute of the taglib command is used to specify the URI for importing the tag library descriptor file.



Reference answer:
Explanation for
the answer:
No
33.
The URI of the Core tag library in the JSTL tag library is http://java.sun.com/jsp/core.


Reference
answer:
Wrong
answer Description:
The taglib instruction URI of the core tag library is http://java.sun.com/jsp/jstl/core

fill in the blank

34. The applicationScope implicit object
of EL represents the Map object used to save attributes in the application domain.

Reference answer:
[applicationScope]
Answer description:
None
35.
Cookie
is an implicit object used to obtain Cookie information.

Reference answer:
【cookie】
Answer explanation:
None
36.
The <c:forEach> tag can iterate the elements in the collection object, including Set, List, Map and
array
, etc.

Reference answer:
[Array]
Answer explanation:
The Core tag library provides a <c:forEach> tag, which is specially used to iterate elements in collection objects, such as Set, List, Map, array, etc. 37. The requestScope
ofEL
isimplicit Object, representing the Map object used to save attributes in the request field.

Reference answer:
[requestScope]
Answer description:
None
38.param
of ELis used to obtain a certain value of the request parameter.

Reference answer:
[param]
Answer description:
None
39.
JSTL tag library is composed of core tag library, internationalization/formatting tag library, XML tag library, function tag library andSQL
tag library

Reference answer:
[SQL tag library]
Answer explanation:
JSTL tag library is composed of 5 tag libraries with different functions. These 5 tag libraries are core tag library, internationalization/format tag library, SQL tag library, XML tag Library and function tag library
40.
If you want to import the Core tag library in the JSP page, you need to use
taglib
instruction.

Reference answer:
[taglib]
Answer explanation:
Before using JTL, you must use the <%@ taglib uri="" prefix=""%> directive at the top of the JSP page to define the referenced tag library and access prefix.
41.implicit objects
in EL.

Reference answer:
[EL Implicit Object]
Answer Explanation:
The identifier of EL cannot start with a number. It cannot be a keyword in EL, such as and, or, gt, etc. Cannot be an EL implicit object such as pageContext. It cannot contain special characters such as single quotation mark ('), double quotation mark ("), minus sign (-) and forward slash (/). 42. The
<
c:set> tag is used to set a value for an object in the program, valid Range not specified defaults to
page
.

Reference answer:
[page]
Answer description:
None
43.a series of characters enclosed
in single or
double quotation marks

Reference answer:
[double quotation marks]
answer description:
no

Guess you like

Origin blog.csdn.net/weixin_48053866/article/details/126323750