Do you know that? 1 in 2 business will have online teams by 2020 next

Contact Email: teammmrem@yahoo.com

<< All Upwork (oDesk) and Elance Tests << Elance test answers << IT & Programming category

Test answers for JSP and Servlets 2020

(107) Last updated: January 27
Elance • IT & Programming
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:



Collapse | Expand

107 Answered Test Questions:

1. Where in JSP page source can EL functions be used?

Answers:

• Within a JSP scriptlet

• In the body of a tag where body-content is set to JSP

• Within a JSP expression

• In the body of a tag where body-content is set to tagdependent

2. 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?

Answers:

• 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

3. Which of the following is not a valid implicit object in a JSP?

Answers:

• context

• request

• response

• out

4. 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?

Answers:

• jsp:forward

• jsp:include

• jsp:param

• jsp:useBean

5. The correct way to create a cookie is:

Answers:

• There is no way to call a cookie

• Cookie cookie = new Cookie("key","value")

• JSP cookie = new JSPCookie("key","value")

• Create new cookie()

6. Which of the following methods is most appropriate to send the large amount of data?

Answers:

• HEAD

• HIDDEN

• POST

• GET

7. JSP's are written in____.

Answers:

• C#

• javascript

• PHP

• Java

8. What is the proper Try Catch clause?

Answers:

• try { } catch () { }

• try [] catch() []

• try() catch()

• catch() { } try { }

9. The correct way to import the text library in your JSP page is:

Answers:

• <%& Page import="java.text.*" %>

• <%() Page import="java.text.*" %>

• <%= Page import="java.text.*" %>

• <%@ page import="java.text.*" %>

10. What is the correct way to test if x is equal to 1?

Answers:

• if(x = 1) { }

• if(x ==+ 1) { }

• if(x += 1) { }

• if(x == 1) { }

11. Data runs between the client and the server via a ___ request.

Answers:

• a sql request

• Kornshell script

• port 1433

• HTTP

12. The correct way to import the input/ouput java library is:

Answers:

• <%@ page import="java.io.*" %>

• <%% Page import="java.io.*" %>

• <%&& Page import="java.io.*" %>

• <%-- Page import="java.io.*" %>

13. A JSP page ends with____.

Answers:

• .jsp

• .vb

• .php

• .cs

14. JavaScript is to the client as JSP is to the ____.

Answers:

• C#

• database

• the server

• smartphone

15. JSP are coded in:

Answers:

• VB.Net

• C#

• Python

• Java

16. Which one is the correct syntax for JSTL?

Answers:

• <%= taglib prefix="c" uri="http..." %>

• <%@ taglib prefix="c" uri="http..." %>

• <%-- taglib prefix="c" uri="http..." %>

• <%() taglib prefix="c" uri="http..." %>

17. JSP caches data on a web server called___.

Answers:

• WildCat

• FaceBook

• MySQL

• Tomcat

18. The correct syntax for a IF statement in Java is:

Answers:

• if <> {}

• if {} ( )

• if () { }

• if [] { }

19. A Servlet runs on ____

Answers:

• the client

• in the browser

• a mobile phone

• the server

20. The correct way to create a string in Java is:

Answers:

• Declare var_str = "this";

• String var_str = "this";

• var_str = String("this");

• var_str = "this";

21. The correct way to create a single line comment is:

Answers:

• ?/ comment

• () comment

• # comment

• // comment

22. Which file is a configuration file for JSP?

Answers:

• Client.xml

• JSP.xml

• web.xml

• HTML.aspx

23. How are JSP comments written?

Answers:

• <%-- comment --%>

• <// comment //>

• < comment />

• <%= comment =>

24. A scriptlet is a piece of code that can be embedded inside the HTML, however it has to be inside which tags?

Answers:

• <@ java code @>

• <$ java code $>

• <# java code #>

• <% java code %>

25. The correct way to instantiate a new date object is:

Answers:

• Date myDate = new Date();

• Declare myDate = new Date();

• myDate = Date();

• Date() myDate[];

26. If you wanted to print out the html from your program, which would you use?

Answers:

• browser.println();

• html.println();

• page.println();

• out.println();

27. A JSP directive has the following form:

Answers:

• <%@ page %>

• <%# Page %>

• <%= Page %>

• <%^ Page %>

28. Which of the following files contains the mapping for <servlet-name> and <servlet-class>?

Answers:

• server.xml

• web.xml

• config.xml

• spring.xml

29. JSP stands for ____.

Answers:

• Java Servlet Pages

• Justified Secure Pages

• Java Server Program

• Java Server Pages

30. HTTP is stateless.  What does that mean?

Answers:

• 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.

31. a JavaBean is basically a:

Answers:

• a http request

• a taglib

• a sql update

• class

32. Service method of a generic servlet takes which of the following parameters?

Answers:

• ServletRequest

• Both ServletRequest & ServletResponse

• ServletResponse

• ServletConfig

33. Which is the best place to define error pages for JSPs?

Answers:

• web.xml

• hibernate.cfg.xml

• server.xml

• context.xml

34. How does container process a JSP page after compilation?

Answers:

• Applet

• HTML

• POJO

• Servlet

35. What is the proper taglib for SQL?

Answers:

• <sql:update> <//sql:update>

• <sql:update> </sql:update>

• <sql:update> </sql:update/>

• <sql|update> </sql=update>

36. Which of the follolwing servlet methods gets called for each client request?

Answers:

• public void destroy()

• ServletConfig getServletConfig()

• public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException{

• public void init() throws ServletException

37. The 3 ways to maintain session between web client and the server are:

Answers:

• HTML, Database, javascript

• Cookies, hidden fields, URL rewrite.

• Cookies, HTML, URL rewrite

• Web server, HTML, ASP

38. When a web browser asks for a JSP page, the first thing the JSP engine does is:

Answers:

• checks to see if the cookies are enabled

• checks to see if the browser is Safari or IE

• see if the page needs to be compiled

• checks to see if HTML 5 is being used

39. To deploy and run JavaServer Pages you need...

Answers:

• a compatible web server with a servlet container

• a compatible web server without a servlet container

• a compatible web server container

40. Another way to track user data between pages is:

Answers:

• ASP

• session

• Cookies

• HTML

• session and Cookies

41. A container invokes ____ method before taking care of any requests.

Answers:

• jspDestroy()

• page_load()

• jspInit()

42. Which of the following is an INVALID JSP action?

Answers:

• jsp:setSession

• jsp:getProperty

• jsp:useBean

• jsp:setProperty

43. 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 ?

Answers:

• Session Scope

• Request Scope

• Application Scope

• Page Scope

44. Which of the following is an INVALID bean(object) scope?

Answers:

• config

• request

• page

• session

45. A JSP comment is ___ in the page code.

Answers:

• not included

• executed first

• highlighted

• promoted

46. If submit a form without mentioning the method type(get or post) and called servlet. which method will invoke? doGet() or doPost().

Answers:

• By default it is a Post request

• By default it is a GET request

47. JSP uses what kind of syntax for an expression?

Answers:

• <% expression %>

• < expression />

• <=% expression %>

• <%= expression %>

48. Which of the following are valid sub-elements of taglib?

Answers:

• Both taglib-uri and taglib-location

• taglib-location

• taglib-uri

• tag-location

49. If a jsp page uses classes from java.util package. Which of the following statements would import the package?

Answers:

• <%@ page import="java.util.*"%>

• <%@ page java="java.util.*"@%>

• <%@import java.util.* %>

• <%import="java.util.*"@%>

50. The JSP container calls the which of the following method if it needs the page to release resources?

Answers:

• jspService()

• jspDestroy()

• jspInit()

• jspRelease()

51. What is the correct definition for <jsp:useBean>?

Answers:

• converts HTML to a class

• none of these options are correct

• tries to find an object, creates it if it does not exist

• does not do anything

52. Which code block is correct?

Answers:

• public myFunc(String name) { return name;}

• None of these

• public string myFunc(String name) { return name;}

• public string myFunc(String name) { }

53. Which of the implicit JSP object represents the servlet configuration information?

Answers:

• response

• pageContext

• config

• request

54. 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?

Answers:

• request

• application

• page

• session

55. JSP renders pages vis a ____ Life Cycle.

Answers:

• Python

• HTML

• Java

• JSP

56. Which of the following actions is a specialized tag that generates the appropriate <OBJECT> or <EMBED> tag to load the Java Plug-in software?

Answers:

• jsp:plugin

• jsp:setProperty

• jsp:useBean

• jsp:getProperty

57. Which of the following is a Scriplet?

Answers:

• <%! declarations %>

• <%-- Comment --%>

• <%= Java expression %>

• <% Java statements %>

58. init() or jspInit() is invoked by the container on a servlet or a jsp?

Answers:

• For each request that causes a new session to be created

• Only once in the life time

• For each request

• For each request that causes a new thread to be created

59. 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

Answers:

• 4

• 1

• 3

• 2

60. What does JSTL stand for?

Answers:

• Java Supports Tag Library

• JavaScript Teacher Library

• Java Server Pages Standard Library

• Just Serve The Library

61. If req  is a reference to an HttpServletRequest and there is no current session, what is true about req.getSession() ?

Answers:

• Invoking req.getSession() will return null

• Invoking req.getSession(true) will return a new session

• Invoking req.getSession(false) will return a new session

• Invoking req.getSession(null) will return a new session

62. Which of the following root element provides the global configuration information for the JSP files in a Web application?

Answers:

• jsp-property-group

• taglib-uri

• jsp-config

• taglib

63. Which of the following is a valid JSP expression?

Answers:

• <%= some-java-expression %>

• <%= some-java-expression ;%>

• <%some-java-expression ;%>

• <%some-java-expression %>

64. Which of the following provides a handle to access page directive attributes in the scripting environment?

Answers:

• context

• pageContext

• config

• application

65. Once the JSP has been requested and the page is loaded and initialized, the JSP engine calls the:

Answers:

• _jspService() method

• jspInit() method

• jspPreRender() method

• jspDestroy() method

66. The Web container creates JSP implicit objects like...

Answers:

• session, request & response but not servletContext

• pageContext and servletContext but not session object

• pageContext, servletContext, session, request & response

67. 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

Answers:

• a and c

• a and d

• c and d

• a only

68. Which of the following methods is abstract in HttpServlet?

Answers:

• doGet

• doPost

• service

• It has no abstract methods

69. Which types can be used in conjunction with HttpServletResponse methods to stream output data?

Answers:

• java.io.FileOutputStream

• java.io.OutputStream

• java.io.PrintWriter

• java.io.PrintStream

70. Objects which when compiled down are contained in (a) ____ file.

Answers:

• txt

• kornshell

• JSP

• jar

71. Which of the following is not a 'page' directive attribute?

Answers:

• extends

• implements

• import

• language

72. 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

Answers:

• 1

• 4

• 3

• 2

73. Which of the following classes has an implementation of getSession method that returns an HttpSession object?

Answers:

• SessionContext

• SessionConfig

• HttpServletRequest

• HttpServletResponse

74. Which of the following is not a valid standard method called as part of the JSP life cycle by the container?

Answers:

• _jspService

• jspInit

• jspDestroy

• jspService

75. Which of the following statement correctly describe attribute 'buffer'?

Answers:

• By default, the page output is buffered with an implementation buffer size no smaller than 80 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 800 MB

• By default, the page output is buffered with an implementation buffer size no smaller than 8 MB

76. 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.

Answers:

• b and c

• a and b

• a only

• b and d

77. When using HTML forms which of the folowing is true for POST method?

Answers:

• POST allows secure data transmission over the http method

• POST method sends data in the body of the request

• The POST method should not be used when large amount of data needs to be transferred

• POST allows users to bookmark URLs with parameters

78. Which of the following methods can be used to get initialization and startup parameters of a servlet?

Answers:

• getServletInfo

• init

• getServletConfig

• service

79. Which of the following is an INVALID implicit EL objects?

Answers:

• pageScope

• session

• requestScope

• applicationScope

80. What results from a call to the getInitParameterNames() method on ServletContext when there are no context parameters set up in the deployment descriptor?

Answers:

• null is returned

• A NoParametersExistException is thrown

• An empty Enumeration object is returned

• An ArrayList object of size zero is returned

81. Which one is not a part of the JSTL library group?

Answers:

• HTML

• XML

• Core

• SQL

82. 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 { }

Answers:

• This is an invalid usage of @WebServlet annotations because of the wrongly formed 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

• This is valid usage of @WebServlet annotations which creates a Servlet with “nullHausServlet” url-pattern value

83. JSP implicit object 'out' is an object of which of the following classes?

Answers:

• DataOutputStream

• JspWriter

• PrintStream

• OutputStream

84. 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

Answers:

• 4

• 2

• 3

• 1

85. 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?

Answers:

• Line 3 is wrong because there is no uri attribute

• Line 3 is wrong because the prefix jsp is reserved for standard actions

• 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://

86. By default, the servlet API uses a ______ to store a session ID.

Answers:

• cookie

• request

• sessionfactory

• session

• response

87. Which from the following client redirect options are valid?

Answers:

• <c:redirect url="http://www.photofuntoos.com"/>

• <c:redirect uri="http://www.photofuntoos.com"/>

• <c:redirect href="http://www.photofuntoos.com"/>

88. Which of the following method is called before the page service any requests?

Answers:

• _jspInit()

• init()

• jspService()

• jspInit()

89. Which of the following is not a valid java bean (POJO) scope in JSP?

Answers:

• session

• application

• response

• request

90. JSP implicit object 'application' is an object of which of the following class?

Answers:

• javax.servlet.ServletConfig

• javax.servlet.Application

• javax.servlet.Context

• javax.servlet.ServletContext

91. 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.

Answers:

• 1 only

• 2 and 3

• 1 and 3

• 2 and 4

92. The http GET, PUT, and DELETE verbs are idempotent. What does the term "idempotent" stand for?

Answers:

• The same operation applied multiple times yields the same result

• The same operation applied multiple times yields different results

• This term has nothing to do with http verbs

• None of the above

93. JSP implicit object 'exception' is an object of which of the following classes?

Answers:

• java.lang.Throwable

• java.lang.JSPException

• java.lang.RunTimeException

• java.lang.Exception

94. 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?

Answers:

• page

• session

• application

• request

95. Which of the following is valid about 'page' JSP directive?

Answers:

• Includes the contents of a file into the JSP at translation time

• Makes a custom tag library available within the including page

• Controls properties of the entire application

• Controls properties of the JSP

96. Which of the following HTTP method sends the same response as request?

Answers:

• DEBUG

• TRACE

• OPTIONS

• HEAD

97. 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");

Answers:

• String s has a valid directory as its value

• The servlet won’t run

• The servlet won’t compile

• String s has a null value

98. 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

Answers:

• 1

• 3

• 2

99. What is the limit of data to be passed from HTML when doGet() method is used?

Answers:

• 1k

• 2k

• 8k

• 4k

100. Which of the following is a non-idempotent HTTP method

Answers:

• POST

• PUT

• DELETE

• GET

• HEAD

101. How can you make the JSP class implement the SingleThreadModel interface?

Answers:

• <%@ page isThreadSafe="false" %>

• <%@ page isThreadSafe="true" %>

• <%@ page ThreadSafe="false" %>

• <%@ page ThreadSafe="true" %>

102. javax.servlet.jsp.JspPage extends which of the following interfaces?

Answers:

• Servlet

• HttpServlet

• HttpJspPage

• GenericServlet

103. What is true about the life cycle of a servlet?

Answers:

• 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.

• 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

104. Which of the following is an INVALID attribute for tag directive?

Answers:

• body-content

• dynamic-attributes

• display-name

• tag-attributes

105. When comparing servlet initialisation parameters to context intialisation parameters, which is true among the following?

Answers:

• Only changes to context initialization parameters in the DD can be accessed without redeploying the web application

• In their respective DD tags, they both have a <param-name> and a <param-value> tag

• Their respective DD tags are both placed directly under the <web-app> tag

• Both can be directly accessed from a JSP

106. <jsp:include page="/servlet/MyServlet" flush="true"/>

Answers:

• Invoke a Servlet from a JSP page.

• forward to another servlet

• Include static page into a JSP page

• throw an exception

• redirect to another resource

107. 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); }

Answers:

• Runtime error because of incorrectly formed parameter to getNamedDispatcher() method.

• DispatcherNotFoundException

• NullPointerException

• ServletB can obtain request attribute javax.servlet.forward.request_uri