These JSP and Servlets multiple-choice questions and their answers will help you strengthen your grip on the subject of JSP and Servlets. You can prepare for an upcoming exam or job interview with these 100+ JSP and Servlets MCQs.
So scroll down and start answering.
A. If myVar is an HttpSession, s is guaranteed to have the value “myVal”
B. The value of s cannot be guaranteed
C. If myVar is a ServletContext, compilation will fail
D. If myVar is an HttpSession, compilation will fail
A. For each request that causes a new session to be created
B. For each request that causes a new thread to be created
C. For each request
D. Only once in the life time
A. jsp:useBean
B. jsp:setProperty
C. jsp:setSession
D. jsp:getProperty
A. Java Servlet Pages
B. Justified Secure Pages
C. Java Server Pages
D. Java Server Program
A. < expression />
B. <=% expression %>
C. <%= expression %>
D. <% expression %>
A. POJO
B. HTML
C. Applet
D. Servlet
A. a taglib
B. a http request
C. a sql update
D. class
A. <@ java code @>
B. <% java code %>
C. <$ java code $>
D. <# java code #>
A. browser.println();
B. page.println();
C. out.println();
D. html.println();
A. WildCat
B. Tomcat
C. MySQL
D. FaceBook
A. PHP
B. C#
C. javascript
D. Java
A. <%% Page import="java.io.*" %>
B. <%@ page import="java.io.*" %>
C. <%-- Page import="java.io.*" %>
D. <%&& Page import="java.io.*" %>
A. database
B. the server
C. C#
D. smartphone
A. try() catch()
B. catch() { } try { }
C. try [] catch() []
D. try { } catch () { }
A. <%@ page import="java.text.*" %>
B. <%= Page import="java.text.*" %>
C. <%& Page import="java.text.*" %>
D. <%() Page import="java.text.*" %>
A. if {} ( )
B. if [] { }
C. if <> {}
D. if () { }
A. VB.Net
B. Java
C. Python
D. C#
A. Date() myDate[];
B. Declare myDate = new Date();
C. myDate = Date();
D. Date myDate = new Date();
A. Kornshell script
B. HTTP
C. port 1433
D. a sql request
A. if(x ==+ 1) { }
B. if(x == 1) { }
C. if(x += 1) { }
D. if(x = 1) { }
A. JSP.xml
B. Client.xml
C. HTML.aspx
D. web.xml
A. <%-- comment --%>
B. <// comment //>
C. < comment />
D. <%= comment =>
A. () comment
B. // comment
C. ?/ comment
D. # comment
A. var_str = String("this");
B. var_str = "this";
C. String var_str = "this";
D. Declare var_str = "this";
A. <%= taglib prefix="c" uri="http..." %>
B. <%@ taglib prefix="c" uri="http..." %>
C. <%-- taglib prefix="c" uri="http..." %>
D. <%() taglib prefix="c" uri="http..." %>
A. the client
B. a mobile phone
C. the server
D. in the browser
A. Javascript holds all the data.
B. All data is stored in the database
C. Once a connection is open then closed, the web server doesn't recognize the request or any past requests.
D. Nothing. Its not an important concept.
A. web.xml
B. spring.xml
C. server.xml
D. config.xml
A. ServletConfig
B. Both ServletRequest & ServletResponse
C. ServletResponse
D. ServletRequest
A. POST
B. HIDDEN
C. GET
D. HEAD
A. <%@ page %>
B. <%^ Page %>
C. <%= Page %>
D. <%# Page %>
A. <sql:update> </sql:update/>
B. <sql:update> </sql:update>
C. <sql|update> </sql=update>
D. <sql:update> <//sql:update>
A. Cookie cookie = new Cookie("key","value")
B. JSP cookie = new JSPCookie("key","value")
C. Create new cookie()
D. There is no way to call a cookie
A. a compatible web server container
B. a compatible web server with a servlet container
C. a compatible web server without a servlet container
A. session and Cookies
B. Cookies
C. HTML
D. ASP
E. session
A. server.xml
B. hibernate.cfg.xml
C. context.xml
D. web.xml
A. By default it is a GET request
B. By default it is a Post request
A. checks to see if HTML 5 is being used
B. see if the page needs to be compiled
C. checks to see if the browser is Safari or IE
D. checks to see if the cookies are enabled
A. Page Scope
B. Session Scope
C. Application Scope
D. Request Scope
A. Cookies, HTML, URL rewrite
B. Web server, HTML, ASP
C. Cookies, hidden fields, URL rewrite.
D. HTML, Database, javascript
A. page_load()
B. jspDestroy()
C. jspInit()
A. ServletConfig getServletConfig()
B. public void init() throws ServletException
C. public void destroy()
D. public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException{
A. highlighted
B. not included
C. promoted
D. executed first
A. jsp:forward
B. jsp:useBean
C. jsp:param
D. jsp:include
A. config
B. page
C. session
D. request
A. tag-location
B. taglib-uri
C. taglib-location
D. Both taglib-uri and taglib-location
A. tries to find an object, creates it if it does not exist
B. none of these options are correct
C. does not do anything
D. converts HTML to a class
A. jspRelease()
B. jspInit()
C. jspDestroy()
D. jspService()
A. <%@import java.util.* %>
B. <%@ page import="java.util.*"%>
C. <%import="java.util.*"@%>
D. <%@ page java="java.util.*"@%>
A. public string myFunc(String name) { return name;}
B. public myFunc(String name) { return name;}
C. None of these
D. public string myFunc(String name) { }
A. config
B. request
C. response
D. pageContext
A. 1
B. 4
C. 3
D. 2
A. JSP
B. HTML
C. Python
D. Java
A. Java Supports Tag Library
B. Just Serve The Library
C. JavaScript Teacher Library
D. Java Server Pages Standard Library
A. jsp:plugin
B. jsp:setProperty
C. jsp:getProperty
D. jsp:useBean
A. jsp-config
B. taglib
C. taglib-uri
D. jsp-property-group
A. <% Java statements %>
B. <%! declarations %>
C. <%= Java expression %>
D. <%-- Comment --%>
A. Invoking req.getSession(false) will return a new session
B. Invoking req.getSession() will return null
C. Invoking req.getSession(true) will return a new session
D. Invoking req.getSession(null) will return a new session
A. pageContext and servletContext but not session object
B. pageContext, servletContext, session, request & response
C. session, request & response but not servletContext
A. application
B. pageContext
C. config
D. context
A. <%some-java-expression %>
B. <%= some-java-expression ;%>
C. <%some-java-expression ;%>
D. <%= some-java-expression %>
A. a and d
B. a and c
C. a only
D. c and d
A. 2
B. 3
C. 4
D. 1
A. By default, the page output is buffered with an implementation buffer size no smaller than 80 MB
B. It indicates whether the content output from the page will be buffered
C. By default, the page output is buffered with an implementation buffer size no smaller than 800 MB
D. By default, the page output is buffered with an implementation buffer size no smaller than 8 MB
A. service
B. doPost
C. doGet
D. It has no abstract methods
A. out
B. context
C. response
D. request
A. _jspService() method
B. jspDestroy() method
C. jspInit() method
D. jspPreRender() method
A. JSP
B. jar
C. kornshell
D. txt
A. java.io.FileOutputStream
B. java.io.PrintStream
C. java.io.OutputStream
D. java.io.PrintWriter
A. extends
B. language
C. implements
D. import
A. SessionContext
B. SessionConfig
C. HttpServletRequest
D. HttpServletResponse
A. jspService
B. _jspService
C. jspDestroy
D. jspInit
A. getServletInfo
B. init
C. service
D. getServletConfig
A. Core
B. XML
C. HTML
D. SQL
A. applicationScope
B. session
C. requestScope
D. pageScope
A. 3
B. 4
C. 2
D. 1
A. b and d
B. b and c
C. a and b
D. a only
A. request
B. response
C. session
D. sessionfactory
E. cookie
A. This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” url-pattern value
B. This is an invalid usage of @WebServlet annotations because of the wrongly formed url-pattern value
C. This code doesn’t compile, because NullHausServlet need to implement one of doGet(-), doPost(-), etc. methods
D. This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” name
A. HEAD
B. TRACE
C. OPTIONS
D. DEBUG
A. DataOutputStream
B. OutputStream
C. PrintStream
D. JspWriter
A. null is returned
B. A NoParametersExistException is thrown
C. An empty Enumeration object is returned
D. An ArrayList object of size zero is returned
A. Line 4 is wrong because the prefix attribute must come before the uri attribute
B. Line 4 is wrong because the uri value must begin with http://
C. Line 3 is wrong because the prefix jsp is reserved for standard actions
D. Line 3 is wrong because there is no uri attribute
A. jspService()
B. _jspInit()
C. init()
D. jspInit()
A. java.lang.Throwable
B. java.lang.Exception
C. java.lang.JSPException
D. java.lang.RunTimeException
A. String s has a valid directory as its value
B. String s has a null value
C. The servlet won’t compile
D. The servlet won’t run
A. None of the above
B. The same operation applied multiple times yields the same result
C. This term has nothing to do with http verbs
D. The same operation applied multiple times yields different results
A. javax.servlet.ServletContext
B. javax.servlet.ServletConfig
C. javax.servlet.Application
D. javax.servlet.Context
A. 2 and 4
B. 1 and 3
C. 2 and 3
D. 1 only
A. Includes the contents of a file into the JSP at translation time
B. Controls properties of the entire application
C. Makes a custom tag library available within the including page
D. Controls properties of the JSP
A. 1
B. 2
C. 3
A. HEAD
B. PUT
C. GET
D. DELETE
E. POST
A. response
B. session
C. request
D. application
A. session
B. page
C. application
D. request
A. In the body of a tag where body-content is set to tagdependent
B. Within a JSP expression
C. Within a JSP scriptlet
D. In the body of a tag where body-content is set to JSP
A. 8k
B. 2k
C. 4k
D. 1k
A. dynamic-attributes
B. display-name
C. body-content
D. tag-attributes
A. GenericServlet
B. HttpServlet
C. Servlet
D. HttpJspPage
A. <%@ page isThreadSafe=
B. <%@ page ThreadSafe=
C. <%@ page ThreadSafe=
D. <%@ page isThreadSafe=
A. Include static page into a JSP page
B. throw an exception
C. Invoke a Servlet from a JSP page.
D. forward to another servlet
E. redirect to another resource