Elance JSP and Servlets Test Answers 2015



Given the following code from a servlet, and given that myvar is a reference to either an HttpSession or a ServletContext: 1. myVar.setAttribute(“myName”, “myVal”); 2. String s = (String) myVar.getAttribute(“myName”); // more code After line 2 executes, which is true?
If myVar is an HttpSession, compilation will fail
The value of s cannot be guaranteed
If myVar is an HttpSession, s is guaranteed to have the value “myVal”
If myVar is a ServletContext, compilation will fail


Which of the following is a valid JSP expression?
<%= some-java-expression %>
<%= some-java-expression ;%>
<%some-java-expression ;%>
<%some-java-expression %>


Which of the following classes has an implementation of getSession method that returns an HttpSession object?
HttpServletResponse
SessionConfig
SessionContext
HttpServletRequest


The Web container creates JSP implicit objects like...
session, request & response but not servletContext
pageContext, servletContext, session, request & response
pageContext and servletContext but not session object


Which of the implicit JSP object represents the servlet configuration information?
request
config
response
pageContext


Which of the following is an INVALID bean(object) scope?
request
page
config
session


If submit a form without mentioning the method type(get or post) and called servlet. which method will invoke? doGet() or doPost().
By default it is a GET request
By default it is a Post request


A JSP comment is ___ in the page code.
not included
promoted
executed first
highlighted


Which of the following are valid sub-elements of taglib?
taglib-location
Both taglib-uri and taglib-location
taglib-uri
tag-location


The JSP container calls the which of the following method if it needs the page to release resources?
jspService()
jspRelease()
jspInit()
jspDestroy()


If a jsp page uses classes from java.util package. Which of the following statements would import the package?
<%@import java.util.* %>
<%import="java.util.*"@%>
<%@ page import="java.util.*"%>
<%@ page java="java.util.*"@%>


Which of the following JSP action can be described as following : Action to substitute the referenced resource's content for the forwarding page's content?
jsp:useBean
jsp:param
jsp:forward
jsp:include


JSP uses what kind of syntax for an expression?
<%= expression %>
<% expression %>
< expression />
<=% expression %>


Which of the following is an INVALID JSP action?
jsp:useBean
jsp:setProperty
jsp:getProperty
jsp:setSession


public class SomeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("a", "value") ; .... } } What would be the scope of a attribute ?
Session Scope
Request Scope
Page Scope
Application Scope


Which of the follolwing servlet methods gets called for each client request?
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException{
public void destroy()
ServletConfig getServletConfig()
public void init() throws ServletException


A container invokes ____ method before taking care of any requests.
jspInit()
page_load()
jspDestroy()


The 3 ways to maintain session between web client and the server are:
Web server, HTML, ASP
HTML, Database, javascript
Cookies, HTML, URL rewrite
Cookies, hidden fields, URL rewrite.


When a web browser asks for a JSP page, the first thing the JSP engine does is:
checks to see if the cookies are enabled
see if the page needs to be compiled
checks to see if HTML 5 is being used
checks to see if the browser is Safari or IE


To deploy and run JavaServer Pages you need...
a compatible web server container
a compatible web server without a servlet container
a compatible web server with a servlet container


Which is the best place to define error pages for JSPs?
hibernate.cfg.xml
web.xml
context.xml
server.xml


JSP stands for ____.
Java Servlet Pages
Java Server Program
Justified Secure Pages
Java Server Pages


How does container process a JSP page after compilation?
POJO
Servlet
HTML
Applet


The correct way to create a cookie is:
Cookie cookie = new Cookie("key","value")
Create new cookie()
There is no way to call a cookie
JSP cookie = new JSPCookie("key","value")


Another way to track user data between pages is:
session
session and Cookies
HTML
Cookies
ASP


a JavaBean is basically a:
a taglib
a http request
a sql update
class


What is the proper taglib for SQL?
<sql|update> </sql=update>
<sql:update> </sql:update>
<sql:update> </sql:update/>
<sql:update> <//sql:update>


Service method of a generic servlet takes which of the following parameters?
Both ServletRequest & ServletResponse
ServletConfig
ServletResponse
ServletRequest


A JSP directive has the following form:
<%^ Page %>
<%# Page %>
<%@ page %>
<%= Page %>


Which of the following files contains the mapping for <servlet-name> and <servlet-class>?
config.xml
web.xml
server.xml
spring.xml


Which of the following methods is most appropriate to send the large amount of data?
HEAD
POST
GET
HIDDEN


A Servlet runs on ____
in the browser
the client
a mobile phone
the server


If you wanted to print out the html from your program, which would you use?
browser.println();
out.println();
page.println();
html.println();


HTTP is stateless. What does that mean?
All data is stored in the database
Once a connection is open then closed, the web server doesn't recognize the request or any past requests.
Javascript holds all the data.
Nothing. Its not an important concept.


A scriptlet is a piece of code that can be embedded inside the HTML, however it has to be inside which tags?
<@ java code @>
<$ java code $>
<% java code %>
<# java code #>


The correct way to instantiate a new date object is:
Date myDate = new Date();
myDate = Date();
Declare myDate = new Date();
Date() myDate[];


How are JSP comments written?
<%-- comment --%>
< comment />
<%= comment =>
<// comment //>


JSP caches data on a web server called___.
MySQL
WildCat
FaceBook
Tomcat


The correct syntax for a IF statement in Java is:
if {} ( )
if [] { }
if () { }
if <> {}


JSP's are written in____.
Java
PHP
C#
javascript


The correct way to create a string in Java is:
var_str = String("this");
var_str = "this";
Declare var_str = "this";
String var_str = "this";


Data runs between the client and the server via a ___ request.
Kornshell script
port 1433
a sql request
HTTP


What is the proper Try Catch clause?
try { } catch () { }
try() catch()
catch() { } try { }
try [] catch() []


The correct way to import the text library in your JSP page is:
<%() Page import="java.text.*" %>
<%= Page import="java.text.*" %>
<%@ page import="java.text.*" %>
<%& Page import="java.text.*" %>


The correct way to import the input/ouput java library is:
<%@ page import="java.io.*" %>
<%&& Page import="java.io.*" %>
<%-- Page import="java.io.*" %>
<%% Page import="java.io.*" %>


Which file is a configuration file for JSP?
HTML.aspx
web.xml
JSP.xml
Client.xml


JavaScript is to the client as JSP is to the ____.
C#
the server
database
smartphone


What is the correct way to test if x is equal to 1?
if(x ==+ 1) { }
if(x += 1) { }
if(x = 1) { }
if(x == 1) { }


The correct way to create a single line comment is:
() comment
# comment
?/ comment
// comment


Which one is the correct syntax for JSTL?
<%() taglib prefix="c" uri="http..." %>
<%-- taglib prefix="c" uri="http..." %>
<%@ taglib prefix="c" uri="http..." %>
<%= taglib prefix="c" uri="http..." %>


JSP are coded in:
Python
VB.Net
C#
Java


A JSP page ends with____.
.php
.cs
.vb
.jsp


What is the correct definition for <jsp:useBean>?
converts HTML to a class
tries to find an object, creates it if it does not exist
none of these options are correct
does not do anything


Which code block is correct?
None of these
public myFunc(String name) { return name;}
public string myFunc(String name) { return name;}
public string myFunc(String name) { }


JSP renders pages vis a ____ Life Cycle.
HTML
Java
JSP
Python


Which of the following object scope is defined as follows : Objects with this scope are accessible from pages processing requests in the same session as the one in which they were created?
request
page
session
application


Which of the following is a Scriplet?
<%! declarations %>
<%= Java expression %>
<%-- Comment --%>
<% Java statements %>


What's the difference between servlets and applets? 1.Servlets executes on Servers, where as Applets executes on Browser 2.Servlets have no GUI, where as an Applet has GUI 3. Both of them 4. None of them
3
4
2
1


What does JSTL stand for?
JavaScript Teacher Library
Java Server Pages Standard Library
Java Supports Tag Library
Just Serve The Library


Which of the following actions is a specialized tag that generates the appropriate <OBJECT> or <EMBED> tag to load the Java Plug-in software?
jsp:getProperty
jsp:setProperty
jsp:useBean
jsp:plugin


If req is a reference to an HttpServletRequest and there is no current session, what is true about req.getSession() ?
Invoking req.getSession(null) will return a new session
Invoking req.getSession() will return null
Invoking req.getSession(true) will return a new session
Invoking req.getSession(false) will return a new session


init() or jspInit() is invoked by the container on a servlet or a jsp?
For each request
For each request that causes a new thread to be created
Only once in the life time
For each request that causes a new session to be created


Which of the following provides a handle to access page directive attributes in the scripting environment?
context
application
pageContext
config


Which of the following root element provides the global configuration information for the JSP files in a Web application?
taglib-uri
jsp-property-group
taglib
jsp-config


When might a JSP get translated (Choose all that apply)? a. When the application is started b. When the developer compiles code in the src folder c. The first time a user requests the JSP d. After jspdestroy() is called, it gets retranslated
a and c
a and d
a only
c and d


Which of the following is not a valid implicit object in a JSP?
response
request
context
out


Which of the following methods is abstract in HttpServlet?
doGet
service
It has no abstract methods
doPost


Once the JSP has been requested and the page is loaded and initialized, the JSP engine calls the:
_jspService() method
jspDestroy() method
jspInit() method
jspPreRender() method


How can you call a servlet to autofill a dropdown list which depends on selection from previous 2 dropdown lists? 1. Print all possible values of the 2nd and 3rd dropdown out as a Javascript object 2. Make use of XMLHttpRequest in Javascript to fire an asynchronous request to a servlet during the onchange event 3. Both of them 4. None of them
1
3
2
4


Which types can be used in conjunction with HttpServletResponse methods to stream output data?
java.io.FileOutputStream
java.io.OutputStream
java.io.PrintStream
java.io.PrintWriter


Objects which when compiled down are contained in (a) ____ file.
jar
JSP
kornshell
txt


Which of the following is not a 'page' directive attribute?
extends
implements
import
language


Which of the following statement correctly describe attribute 'buffer'?
By default, the page output is buffered with an implementation buffer size no smaller than 8 MB
By default, the page output is buffered with an implementation buffer size no smaller than 800 MB
It indicates whether the content output from the page will be buffered
By default, the page output is buffered with an implementation buffer size no smaller than 80 MB


When using HTML forms which of the folowing is true for POST method?
POST allows secure data transmission over the http method
POST method sends data in the body of the request
POST allows users to bookmark URLs with parameters
The POST method should not be used when large amount of data needs to be transferred


Which of the following methods can be used to get initialization and startup parameters of a servlet?
getServletConfig
init
getServletInfo
service


Which from the following client redirect options are valid?
<c:redirect href="http://www.photofuntoos.com"/>
<c:redirect url="http://www.photofuntoos.com"/>
<c:redirect uri="http://www.photofuntoos.com"/>


Which statements are true: a. The element (subelement of ) set to “false” forces the container to make the servlet unreachable for request to the defined url-pattern, b. The element (subelement of ) set to “false” forces the container to make the request for the servlet respond with HTTP Code 503 (Service unavailable), c. The web fragment is merged into the final Deployment Descriptor after the web fragment related annotations are processed, d. All web fragments are processed together (in a batch) and all are merged into the final Deployment Descriptor before the web fragments’ related annotations are processed.
a only
a and b
b and d
b and c


Which of the following is not a valid standard method called as part of the JSP life cycle by the container?
jspService
jspInit
jspDestroy
_jspService


Which one is not a part of the JSTL library group?
HTML
SQL
XML
Core


What results from a call to the getInitParameterNames() method on ServletContext when there are no context parameters set up in the deployment descriptor?
An empty Enumeration object is returned
An ArrayList object of size zero is returned
null is returned
A NoParametersExistException is thrown


Which of the following is an INVALID implicit EL objects?
applicationScope
requestScope
session
pageScope


Considering the following Servlet code, choose the statement which is true: package com.nullhaus; import javax.servlet.annotation.*; import javax.servlet.http.*; @WebServlet("nullHausServlet") public class NullServlet extends HttpServlet { }
This is an invalid usage of @WebServlet annotations because of the wrongly formed url-pattern value
This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” url-pattern value
This code doesn’t compile, because NullHausServlet need to implement one of doGet(-), doPost(-), etc. methods
This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” name


Which methods are needed to get the complete and exact URL that causes the call to arrive at the servlet? 1. getRequestURL() 2. getQueryString() 3. Both of them 4. None of them
4
3
2
1


JSP implicit object 'out' is an object of which of the following classes?
PrintStream
DataOutputStream
JspWriter
OutputStream


By default, the servlet API uses a ______ to store a session ID.
response
sessionfactory
request
cookie
session


JSP implicit object 'application' is an object of which of the following class?
javax.servlet.ServletContext
javax.servlet.Application
javax.servlet.ServletConfig
javax.servlet.Context


Given: 1. <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %> 2. <%@ taglib prefix = “tables” uri= http://www.javaranch.com/tables %> 3. <%@ taglib prefix = “jsp” tagdir=”/WEB_INF/tags” %> 4. <%@ taglib uri=”UtilityFunctions” prefix=”util” %> What about the above taglib directives would cause the JSP to not function?
Line 4 is wrong because the prefix attribute must come before the uri attribute
Line 4 is wrong because the uri value must begin with http://
Line 3 is wrong because there is no uri attribute
Line 3 is wrong because the prefix jsp is reserved for standard actions


The http GET, PUT, and DELETE verbs are idempotent. What does the term "idempotent" stand for?
None of the above
The same operation applied multiple times yields the same result
This term has nothing to do with http verbs
The same operation applied multiple times yields different results


Which of the following method is called before the page service any requests?
_jspInit()
jspInit()
init()
jspService()


Which of the following is not a valid java bean (POJO) scope in JSP?
session
request
response
application


JSP implicit object 'exception' is an object of which of the following classes?
java.lang.Exception
java.lang.Throwable
java.lang.RunTimeException
java.lang.JSPException


Which of the following HTTP method sends the same response as request?
DEBUG
HEAD
OPTIONS
TRACE


A programmer needs to update a live, running servlet’s initialization parameters so that the web application will begin to use the new parameters immediately. In order to accomplish this, which must be true (although not necessarily sufficient)? 1. The container must destroy and then reinitialize the servlet 2. The servlet’s constructor must retrieve the updated DD parameter from the servlet’s ServletConfig object 3. For each parameter, the DD must have a separate <init-param> tag 4. For each parameter, you must modify a DD tag that specifies the name of the servlet, the name of the parameters, and the new value of the parameter.
1 only
1 and 3
2 and 3
2 and 4


Where in JSP page source can EL functions be used?
Within a JSP expression
Within a JSP scriptlet
In the body of a tag where body-content is set to tagdependent
In the body of a tag where body-content is set to JSP


Which of the following is valid about 'page' JSP directive?
Makes a custom tag library available within the including page
Controls properties of the JSP
Controls properties of the entire application
Includes the contents of a file into the JSP at translation time


Given a servlet containing the following code, what is the outcome of attempting to compile and run the servlet? ServletContext context = getServletContext(); String s = context.getAttribute("javax.servlet.context.tempdir");
String s has a null value
The servlet won’t compile
The servlet won’t run
String s has a valid directory as its value


Why do you get this error? NoClassDefFoundError: org.apache.commons.lang.StringUtils. 1. The given class could not be found. 2. The given class could be found, but something went wrong when initializing it 3. None of them
3
2
1


Which of the following object scope is defined as follows : Objects with this scope are accessible from pages processing requests in the same application as the one in which they were created?
request
application
page
session


Which of the following is a non-idempotent HTTP method
GET
DELETE
HEAD
PUT
POST


What is the limit of data to be passed from HTML when doGet() method is used?
8k
2k
4k
1k


javax.servlet.jsp.JspPage extends which of the following interfaces?
HttpJspPage
Servlet
GenericServlet
HttpServlet


<jsp:include page="/servlet/MyServlet" flush="true"/>
Include static page into a JSP page
throw an exception
forward to another servlet
redirect to another resource
Invoke a Servlet from a JSP page.


When comparing servlet initialisation parameters to context intialisation parameters, which is true among the following?
Only changes to context initialization parameters in the DD can be accessed without redeploying the web application
Both can be directly accessed from a JSP
Their respective DD tags are both placed directly under the <web-app> tag
In their respective DD tags, they both have a <param-name> and a <param-value> tag


Which of the following is an INVALID attribute for tag directive?
tag-attributes
display-name
dynamic-attributes
body-content


How can you make the JSP class implement the SingleThreadModel interface?
<%@ page ThreadSafe="true" %>
<%@ page isThreadSafe="false" %>
<%@ page ThreadSafe="false" %>
<%@ page isThreadSafe="true" %>


What is true about the life cycle of a servlet?
The service() method is invoked by either doPost() or doGet() after they’ve completed a request
The destroy() method is invoked after every invocation of doGet() compiles
Each time doPost() is invoked, it runs in its own thread
The service() method is the first method invoked by the container when a new request is received.


What is the likely outcome from running the code below? protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = getServletContext().getNamedDispatcher("/ServletB"); dispatcher.forward(request, response); }
ServletB can obtain request attribute javax.servlet.forward.request_uri
Runtime error because of incorrectly formed parameter to getNamedDispatcher() method.
NullPointerException
DispatcherNotFoundException

No comments:

Post a Comment