JSP technical exercises

multiple choice

1.
The default value of the attribute Language of the JSP Page compilation instruction is ().

A, Java
B, C
C, C#
D, SQL
reference answer:
A
Answer description:
None
2.
In JSP, the attribute of the page instruction is used to introduce the required package or class ().

A, extends
B, import
C, languge
D, scontentType
reference answer:
B
answer description:
The import attribute is used to specify the package or class imported in the Servlet source file translated into the JSP page. import is the only page directive attribute that can be declared multiple times. An import attribute can refer to multiple classes, separated by commas.
3.
After the jsp is translated into Servlet source code, the method that will be called when the user accesses the jsp file is ().

A. _jspInit()
B. _jspDesroy()
C. _jspService()
D. Service()
Reference answer:
C
Answer description:
The JSP container first converts the JSP file into a Java source file (Java Servlet source program), during the conversion process , if any grammatical error is found in the JSP file, the conversion process is interrupted and an error message is returned to the server and the client. If the conversion is successful, the JSP container compiles the generated Java source file into a corresponding bytecode file *.class. The class file is a Servlet, and the Servlet container will handle it like any other Servlet.
4.
The content in the tag <% %> is ().

A. script script
B. JSP program fragment
C. JSP statement
D. JSP expression
reference Answer:
B
Answer description:
None
5.
Which of the following is not an attribute of the page instruction ().

A, .import
B, pageEncoding
C, errorPage
D, content
Reference answer:
D
Answer explanation:
import: specify the package or class imported in the Servlet source file translated from the JSP page. pageEnCoding: Specifies the page encoding format. errorPage: Specifies an error page.
6.
The JSP object that can realize data sharing between different web pages, and can also realize cross-machine sharing of data is ().

A. Response object
B. Session object
C. Application object
D. Request object
reference answer:
C
Answer description:
Response object: the response information from the server to the client; Session object: save the user's information; Request object: get the user request information;
7.
The tag that can dynamically import other pages in JSP is ().

A. <%include/>
B. <%@ include%>
C. jsp:importPage/
D. jsp:include/
Reference answer:
D
Answer description:
None
8.
The class corresponding to the JSP implicit object pageContext is ().

A. javax.servlet.http.PageContext
B. javax.servlet.jsp.PageContext
C. javax.servlet.http.jsp.PageCpntext
D. javax.servlet.jsp.http.PageContext
Reference Answer:
B
Answer Description:
None
9.
The following is not a JSP implicit object ().

A, request
B, out
C, context
D, session
Reference answer:
C
Answer explanation:
JSP implicit object: (1) out is used for page output (2) request obtains user request information (3) response server responds information to the client (4) config server configuration, which can obtain initialization parameters (5) session is used to save user information (6) application shared information of all users (7) page refers to the instance of the Servlet class converted from the current page (8) pageContext of JSP Page container (9) exception Indicates the exception that occurs on the JSP page, and only works in the error page
10.
Which instruction of JSP allows the page user to customize the tag library? ()

A. include instruction
B. taglib instruction
C. page instruction
D. plugin instruction reference
answer:
B
answer description :
none

A. <jsp:forward file="relativeURL" />
B. <jsp:forward path="relativeURL" />
C. <jsp:forward page="relativeURL" />
D. <%@include file="relativeURL" />
Reference answer:
C
Answer explanation:
None
12.
Which of the following page instructions is legal? ()

A. <%page language="java"%>
B. <%! page language="java"%>
C. <%@ page language="java"%>
D. <%@Page language="java"% >
Reference answer:
C
Answer description:
None
13.
Which of the following tags can be inserted between variable and method declarations? ( )

A, <% and %>
B, <%! And %>
C, </ and %>
D, <% and! >
Reference answer:
B
Answer explanation:
A is a JSP code fragment; C and D are not written correctly
14.
In JSP, the method definition must be placed ()middle.

A. Form
B. JSP script statement
C. JSP script code segment
D. JSP script expression
reference Answer:
B
Answer description:
None
15.
The java.util.* package needs to be introduced into the jsp page, and the command to be used is ( ).

A. <%@page import="java.util. " %>
B. <%@include package="java.util.
" %>
C. <%@import package="java.util. " %>
D. <%@page package="java.util.
" %>
Reference answer:
A
Answer description:
None
16.
In the life cycle of JSP, the method used for initialization is ()

A. doPost()
B. doGet()
C. init()
D. destroy()
Reference answer:
C
Answer description:
None
17. Regarding
the statement about JSP hidden comments, the correct one is ().

A. Visible on the browser side, visible on the server side
B. Invisible on the browser side, visible on the server side
C. Visible on the browser side, invisible on the server side
D. Invisible on the browser side, invisible on the server side
Reference answer:
D
Answer description :
JSP provides hidden comments, hidden comments are not only invisible in browser pages, but also invisible when viewing HTML source code, so hidden comments have higher security.
18.
Read the following JSP code snippet: <% int x=5; %> <%! private int m(int a){ return a+1;} %> <% x=3; %> x=<%=x %>,<%=m(x)%> The result of its operation is ()

A, x=3,6
B, x=3,4
C, x=5,4
D, compilation error
reference answer:
B
answer description:
no
19,
read the following code snippet: <% out.println("first line " ); response.getWriter().write("second line "); %> What will happen when the browser is used to access the jsp page ()

A. Output the above code as it is
B. First line
C. First output the first line, then output the second line
D. First output the second line, and then output the first line
Reference answer:
D
Answer explanation:
After the out object writes data through the print statement, Until the end of the entire JSP page, the data of the input buffer in the out object (namely: first line) is actually written into the buffer provided by the Serlvet engine, and the response.getWriter().println() statement directly writes the content ( That is: second line) is written into the buffer provided by the Servlet engine, and the Servlet engine outputs the content in the order in which the data in the buffer is stored.
20.
The following are some attributes in the page command, among them, the attribute used to tell the client browser what document type to use is ()

A, session
B, contentType
C, content
D, isThreadSafe
reference answer:
B
answer description:
session is used to specify whether the JSP has a built-in Session object; the contentType attribute is used to specify the MIME type and character encoding of the current JSP page, for example: HTML format text/html, JPG image is image/jpeg;
21.
In JSP, the class corresponding to the exception implicit object is ()

A. java.lang.Exception
B. java.lang.Throwable
C. java.lang.ExceptionThrowable
D. java.lang.ThrowableException
Reference answer:
A
Answer description:
None

multiple choice

22.
Among the following statements about jsp, the wrong one is ().

A. The content of JSP will be sent directly to the browser, which will be interpreted and run by the browser.
B. JSP looks like HTML, so it is a kind of static web resource.
C. Every time the browser visits the JSP page, the JSP The engine will translate the JSP page into Servlet
D. If Servlet is to embed HTML in java code, then JSP is to embed java code in HTML.
Reference answer:
A, B, C
Answer explanation:
The full name of JSP is Java Server Pages, i.e. Java Server Pages. It is a higher level extension of Servlet. In the JSP file, the HTML code and the Java code coexist, wherein the HTML code is used to realize the display of the static content in the web page, and the Java code is used to realize the display of the dynamic content in the web page. Eventually, the JSP file will be compiled into a Servlet by the Web container of the Web server to handle various requests.
23.
The following statement about the value of the scope of the pageContext object is correct ().

A. pageContext.PAGE_SCOPE: Indicates the page scope
B. pageContext.REQUEST_SCOPE: Indicates the request scope
C. pageContext.SESSION_SCOPE: Indicates the session scope
D. pageContext.APPLICATION_SCOPE: Indicates the Web application scope
Reference answer:
A, B, C, D
Answer description :
None
24.
Regarding the difference between the include instruction and the jsp:include element, the correct one is ().

A. The include command specifies the included file through the file attribute, and the jsp:include element specifies the included file through the page attribute. B. The include file
of the include command cannot have variables or methods with the same name, and the jsp:include element includes the file in the file There can be variables or methods with the same name
C. When using the include command, the content of the included file will be inserted into the containing page; when using the jsp:include element to include the file, when the element is executed, the program will forward the request to the included page Included page
D, the above statements are not correct
Reference answer:
A, B, C
Answer description:
None
25.
Which stages have you gone through in the JSP life cycle ()

A. Compilation phase
B. Initialization phase
C. Execution phase
D. Destruction phase
Reference answer:
A, B, C, D
Answer description:
None

True or False

26.
HTML can be used in jsp files.

Reference answer:
Description of
the answer:
None
27.
The attribute names of the page directive are case-sensitive.

Reference answer:
Explanation to
the answer:
No
28.
The hidden comments of JSP can be seen on the server side.

Reference answer:
Wrong
answer description:
JSP provides hidden comments. Hidden comments are not only invisible in browser pages, but also invisible when viewing HTML source code, so hidden comments have higher security.
29.
<!%%> is used to define methods in jsp.

Reference answer:
Description of
the answer:
None
30.
The default value of the flush attribute of the jsp:include element is false.

Reference answer:
Explanation for
the answer:
None
31.
Among the attributes of the page directive, all attributes can only appear once, otherwise the compilation will fail.

Reference answer:
Wrong
answer explanation:
The import attribute is the only page instruction attribute that can be declared multiple times.
32.
JSP files are different from html files, and they cannot be run directly in the browser.

Reference answer:
Description of
the answer:
None
33.
The method declared in the JSP declaration statement is valid in the entire JSP page, but the variables defined in the method are only valid in the method.

Reference answer:
Description of
the answer:
None
34.
The include command is used to statically include a file, and its file attribute can only take a relative path.

Reference answer:
Explanation to
the answer:
The include directive has only one file attribute, which is used to specify the path of the file to be included. It should be noted that the path of the inserted file generally does not start with "/", but uses a relative path.
35.
The jsp:forward element can forward the current request to other web pages. After the request is forwarded, the current page will no longer be executed, but the target page specified by this element will be executed.

Reference answer:
Explanation for
the answer:
No
36,
<%out.print("output")%> and System.out.print("output"), the output positions of the two are the same.

Reference answer:
Wrong
answer description:
The former is output in the browser, and the latter is output in the console.
37.
A JSP page can include content such as instruction mark, HTML code, JavaScript code, embedded Java code, comment and JSP action mark.

Reference answer:
Explanation to
the answer:
No
38.
In the JSP file, there are HTML code and Java code at the same time.

Reference answer:
Explanation to
the answer:
The full name of JSP is Java Server Pages, that is, Java Server Pages. It is a higher level extension of Servlet. In the JSP file, the HTML code and the Java code coexist, wherein the HTML code is used to realize the display of the static content in the web page, and the Java code is used to realize the display of the dynamic content in the web page.
39.
Every time a user visits a JSP page, the page will be translated into a Servlet source file by JspServlet, and then the source file will be compiled into a .class file.

Reference answer:
Wrong
answer description:
The JSP container first converts the JSP file into a Java source file (Java Servlet source program). and the client returns an error message. If the conversion is successful, the JSP container compiles the generated Java source file into a corresponding bytecode file *.class. The class file is a Servlet, and the Servlet container will handle it like any other Servlet.
40.
When the findAttribute() method of the pageContext object is called, the name attribute will be searched for in the order of page, request, session, and application.

Reference answer:
Explanation to
the answer:
None
41.
The JSP implicit object out can be obtained through response.getWriter(), and then send text content to the page through the println() or write() method.

Reference answer:
Wrong
answer description:
In a JSP page, writing data through the out implicit object is equivalent to inserting data into the buffer of the JspWriter object. Only when the ServletResponse.getWriter() method is called, the data in the buffer can be real Write to the buffer provided by the Servlet engine.

fill in the blank

42.
There are 3 kinds of comments for the code fragments embedded in JSP, which are single-line comments,
multi-line comments
and prompt document comments.

Reference answer:
[Multi-line comments]
Answer explanation:
Comments in JSP code fragments are the same as Java comments, including 3 cases.
43.
The full name of JSP is Java Server Page, which is a
the Servlet
specification.

Reference answer:
[Servlet]
Answer description:
No
44.
In addition to the forward() method of the RequestDispatcher interface, forwarding can also be achieved through the JSP
:forward
tag of JSP.

Reference answer:
[jsp:forward]
Answer explanation:
The jsp:forward action element can forward the current request to other web resources (HTML pages, JSP pages, Servlets, etc.). After the request is forwarded, the current page will no longer be executed, but Executes the target page specified by this element.
45.
Among the JSP instructions, the instruction used to define a tag library and its custom tag prefix is
​​the taglib instruction
.

Reference answer:
【taglib】
Answer explanation:
In the JSP file, the tag library used in the page can be identified through the taglib instruction, and the tag library can be referenced at the same time, and the prefix of the tag can be specified. After the tag library is referenced in the page, the tags in the tag library can be referenced through the prefix.
46.
​​When a file needs to be statically included in the JSP page,
include
command can be used to achieve it.

Reference answer:
[include]
Answer explanation:
In actual development, sometimes it is necessary to include another JSP page in a JSP page. At this time, it can be realized through the include command.
47.
JSP script elements mainly include three types: JSP Scirptlets, declaration flags and
JSP expressions
.

Reference answer:
[JSP expression]
Answer description:
None
48.
The out object in the JSP page is used to
to the client
.

Reference answer:
[Client]
Answer explanation:
In JSP pages, it is often necessary to send text content to the client, and sending text content to the client can be realized by using the out object. The out object is an instance object of the javax.servlet.jsp.JspWriter class, and its function is very similar to the PrintWriter object returned by the ServletResponse.getWriter() method, both of which are used to send entity content in the form of text to the client.
49.
In the JSP page, it is often necessary to process some exception information. At this time, it can be realized through
exception
object.

Reference answer:
[exception]
Answer explanation:
In JSP pages, it is often necessary to process some exception information, which can be realized through the exception object. The exception object is an instance object of the java.lang.Exception class, which is used to encapsulate the exception information thrown in JSP.
50.
Among the JSP instructions, the instruction used to define the attributes related to the page is
the page instruction
.

Reference answer:
【page】
Answer description:
None

Guess you like

Origin blog.csdn.net/weixin_48053866/article/details/126323653
jsp