JSP Mock Test



This section presents you various set of Mock Tests related to JSP Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

JSP Mock Test II

Q 1 - Which of the following attributes are mandatory in <jsp:getProperty /> tag?

A - name, property

B - type, id

C - name, type

D - id, property

Answer : A

Explaination

The getProperty action is used to retrieve the value of a given property and converts it to a string, and finally inserts it into the output.

Q 2 - Which of the following attributes are mandatory in <jsp:setProperty /> tag?

A - name, property

B - type, id

C - name, type

D - id, property

Answer : A

Explaination

The setProperty action sets the properties of a Bean. The Bean must have been previously defined before this action.

Q 3 - Which of the following attributes are mandatory in <jsp:useBean /> tag?

A - id, type

B - id, class

C - type, class

D - type,property

Answer : B

Explaination

The useBean action first searches for an existing object utilizing the id and scope variables. If an object is not found, it then tries to create the specified object using class.

Answer : A

Explaination

The scope attribute identifies the lifecycle of the Action element. It has four possible values: (a) page, (b) request, (c) session, and (d) application.

Q 10 - Which of the following attribute is used to have uncaught run-time exceptions automatically forwarded to an error processing page?

A - error

B - errorPage

C - exception

D - exceptionPage

Answer : B

Explaination

<%@ page errorPage="error.jsp" %>

It will redirect the browser to the JSP page error.jsp if an uncaught exception is encountered during request processing.

Q 11 - Which of the following attribute is used to mark a page as error processing page?

A - isErrorPage

B - errorPage

C - exception

D - exceptionPage

Answer : A

Explaination

<%@ page isErrorPage="true" %>

Within jsp, indicate that it is an error-processing page, using the above directive.

Q 12 - Which of the following attributes are used in <jsp:include /> tag?

A - id, type

B - page, flush

C - type, class

D - type,page

Answer : B

Explaination

<jsp:include /> lets you insert files into the page being generated. The syntax looks like this −

<jsp:include page="relative URL" flush="true" />

Where page is the relative URL of the page to be included. Flush is the boolean attribute the determines whether the included resource has its buffer flushed before it is included.

Q 13 - Which of the following is not a jsp directive?

A - include

B - page

C - scriptlet

D - useBean

Answer : C

Explaination

scriptlet is not a jsp directive.

Q 14 - Which of the following is an implicit object?

A - pageContext

B - servletContext

C - httpContext

D - sessionContext

Answer : A

Explaination

pageContext is an implicit object.

Q 15 - isErrorPage is by default true.

A - True

B - False

Answer : B

Explaination

isErrorPage is required to be set true, it is false by default.

Answer : A

Explaination

The out implicit object is an instance of a javax.servlet.jsp.JspWriter object and is used to send content in a response.

Answer : A

Explaination

The application object is direct wrapper around the ServletContext object for the generated Servlet and in reality an instance of a javax.servlet.ServletContext object.

Answer : B

Explaination

The config object is an instantiation of javax.servlet.ServletConfig and is a direct wrapper around the ServletConfig object for the generated servlet.

Answer : C

Explaination

The pageContext object is an instance of a javax.servlet.jsp.PageContext object. The pageContext object is used to represent the entire JSP page.

Q 20 - Which of the following method can be used to read a form parameter in JSP?

A - request.getParameter()

B - response.getParameter()

C - request.getValue()

D - response.getValue()

Answer : A

Explaination

You call request.getParameter() method to get the value of a form parameter.

Q 21 - Which of the following method can be used to read a multiple values with same name, for example check box selections?

A - request.getParameter()

B - response.getParameter()

C - request.getParameterValues()

D - response.getParameterValues()

Answer : C

Explaination

You call request.getParameterValues() method to get the value of a form parameter if the parameter appears more than once and returns multiple values.

Q 22 - Which of the following method can be used to read parameters names?

A - request.getParameter()

B - response.getParameter()

C - request.getParameterNames()

D - response.getParameterNames()

Answer : C

Explaination

You call request.getParameterNames() method to get the names of all the parameters passed.

Q 23 - Which of the following method can be used to read binary data stream coming from the client?

A - request.getInputStream()

B - response.getInputStream()

C - request.getInputStreamData()

D - response.getInputStreamData()

Answer : A

Explaination

You call request.getInputStream() method to read binary data stream coming from the client for example, image file uploaded.

Answer : C

Explaination

JSP Filters are Java classes that can be used in JSP Programming for both of the above purposes.

Answer : A

Explaination

Filters are defined in the deployment descriptor file web.xml and then mapped to either servlet or JSP names or URL patterns in your application's deployment descriptor.

Answer Sheet

Question Number Answer Key
1 A
2 A
3 B
4 A
5 C
6 A
7 B
8 D
9 C
10 B
11 A
12 B
13 C
14 A
15 B
16 A
17 A
18 B
19 C
20 A
21 C
22 C
23 A
24 C
25 A
jsp_questions_answers.htm
Advertisements