Servlet Flashcards

1
Q

GenericServlet implements Servlet interface.
Select one:
a. True
b. False

A

a. True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
How do you write a message back to the browser from inside a Servlet?
Select one:
a. HttpWriter out = response.getHttpWriter( ) out.println(HTML code)
b. BufferedWriter writer = new BufferedWriter(new FileWriter()) writer.write(HTML code)
c. PrintWriter out = response.getWriter( ) out.println(HTML code) 
d. HtmlWriter out = response.get HtmlWriter ( ) out.println(HTML code)
A

c. PrintWriter out = response.getWriter( ) out.println(HTML code)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How many times are each lifecycle method of a servlet called?
Select one:
a. init once per request, service once per request, destroy once per request
b. init once per request, service once per request, destroy once
c. init once, service once, destroy once
d. init once, service once per request, destroy once

A

c. init once, service once, destroy once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
How would you pre-initialize a servlet?
Select one:
a. Override the init(ServletConfig config) method 
b. Override the init( ) method
c. You cannot pre-initialize a servlet
d. Use the load-on-startup tag
A

b. Override the init( ) method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False. When a servlet throws an exception, the web container searches the configurations in web.xml that use the exception-type element for a match with the thrown exception type.
Select one:
a. True
b. False

A

a. True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
What file is used to map servlet configuration information? Write its full relative path.
Select one:
a. web.xml
b. servlet.xml
c. WEB/INF/web.xml
d. WEB-INF/web.xml
A

d. WEB-INF/web.xml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is not a property of a well-formed XML document?
Select one:
a. All tags should be properly nested
b. Empty tags are necessary to close with a forward slash
c. XML tags are case sensitive
d. Every start tag does not need an end tag

A

d. Every start tag does not need an end tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between HTTP GET and POST methods?
Select one:
a. GET requests do not remain in the browser history
b. GET requests have no restrictions on data length
c. POST requests cannot be bookmarked
d. GET requests are never cached

A

c. POST requests cannot be bookmarked

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between request.getRequestDispatcher forward and response sendRedirect?
Select one:
a. Forward is performed internally by the client
b. Forward is marginally slower than a redirect, since it requires two browser requests, not one
c. With forward, objects placed in the original request scope are not available to the second request
d. Browser is completely unaware that a forward has taken place, so its original URL remains intact

A

d. Browser is completely unaware that a forward has taken place, so its original URL remains intact

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between ServletConfig and ServletContext?
Select one:
a. ServletContext object is only available in a Servlet and not a JSP.
b. ServletContext is available to all servlets. ServletConfig is available to only one servlet.
c. ServletConfig is available to all servlets. ServletContext is available to only one servlet.
d. ServletConfig object is only available in a JSP.

A

b. ServletContext is available to all servlets. ServletConfig is available to only one servlet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between the no-arg init( ) method and the init(ServletConfig config) method?
Select one:
a. Servlets do not have an init( ) method
b. Servlets do not have an init(ServletConfig config) method
c. init(ServletConfig config) is a convenience method meant to be overridden
d. init(ServletConfig config) is called by the Servlet Container to initialize a servlet

A

d. init(ServletConfig config) is called by the Servlet Container to initialize a servlet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the method signature of the doPost method?
Select one:
a. protected void doPost(HttpServletRequest request, HttpServletResponse response)
b. public PrintWriter doPost(HttpServletRequest request)
c. public void doPost(HttpServletRequest request, HttpServletResponse response)
d. protected HttpServletResponse doPost(HttpServletRequest request)

A

a. protected void doPost(HttpServletRequest request, HttpServletResponse response)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
Which code will retrieve all the cookies sent in an HTTP message?
Select one:
a. request.getSession( ).getCookies( )
b. response.getCookies( )
c. this.getCookies( )
d. request.getCookies( )
A

d. request.getCookies( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
Which code will store a cookie on the client computer?
Select one:
a. request.addCookie( )
b. response.addCookie( ) 
c. this.putCookie( )
d. request.getSession( ).putCookie( )
A

b. response.addCookie( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
Which is NOT a JSTL core library function?
Select one:
a. if
b. forEach
c. choose
d. formatNumber
A

d. formatNumber

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which is NOT a way to invalidate a session?
Select one:
a. Add deployment descriptor in web.xml using session-timeout tag
b. Use the session.invalidate( ) method.
c. Set the max inactive interval for the session to the desire amount. Session is then automatically terminated
d. Implement a log-out feature in your application.

A

d. Implement a log-out feature in your application.

17
Q
Which tag in web.xml is used to add values to the ServletConfig object?
Select one:
a. servlet-param 
b. init-param
c. context-param
d. config-param
A

b. init-param

18
Q
Which tag in web.xml is used to add values to the ServletContext object?
Select one:
a. context-param
b. config-param
c. servlet-param
d. init-param
A

a. context-param

19
Q
Which tags are used to register a servlet in web.xml?
Select one:
a. servlet, servlet-name, servlet-class 
b. servlet, servlet-name
c. servlet
d. servlet, servlet-class
A

a. servlet, servlet-name, servlet-class