0% found this document useful (0 votes)
191 views

Advanced Programming2019

This document contains a multiple choice question test with 45 questions related to Java servlets, JSP, HTTP, and web application fundamentals. The questions cover topics like session tracking methods, the servlet lifecycle, filters, cookies, request and response objects, and features of web.xml and other deployment descriptors.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

Advanced Programming2019

This document contains a multiple choice question test with 45 questions related to Java servlets, JSP, HTTP, and web application fundamentals. The questions cover topics like session tracking methods, the servlet lifecycle, filters, cookies, request and response objects, and features of web.xml and other deployment descriptors.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Answer all questions.

Show your work so that partial credits may be assigned


Q#1 (10 Marks)
1. Which of the below is not a session tracking method?
a) URL rewriting
b) History
c) Cookies
d) Hidden form
2. Which of the following is stored at client side?
a) URL rewriting
b) Hidden form fields
c) SSL sessions
d) Cookies
3. Which method creates unique fields in the HTML which are not shown to the user?
a) User authentication
b) URL writing
c) HTML Hidden field
d) HTML invisible field
4. Which cookie it is valid for single session only and it is removed each time when the user
closes the browser?
a) Persistent cookie
b) Non-persistent cookie
c) All the above
d) None of the above
5. Sessions is a part of the Session Tracking and it is for maintaining the client state at server
side.
a) True
b) False
6. What is the lifecycle of a servlet?
a) Servlet class is loaded
b) Servlet instance is created
c) init,Service,destroy method is invoked
d) All mentioned above
7. Which method in session tracking is used in a bit of information that is sent by a web server to
a browser and which can later be read back from that browser?
a) HttpSession
b) URL rewriting
c) Cookies
d) Hidden form fields
8. Dynamic interception of requests and responses to transform the information is done by
a) Servlet filter
b) Servlet config
c) Servlet container
d) Servlet context
9. When destroy() method of a filter is called?
a) The destroy() method is called only once at the end of the life cycle of a filter
b) The destroy() method is called after the filter has executed doFilter method
c) The destroy() method is called only once at the begining of the life cycle of a filter
d) The destroyer() method is called after the filter has executed
10. Which of the scripting of JSP not putting content into service method of the converted
servlet?
a. Declarations
1
b. Scriptlets
c. Expressions
d. None of the above

11. The difference between Servlets and JSP is the …………….


a. translation
b. compilation
c. syntax
d. Both A and B
12. Which object is used by the filters to get the next component invoked?
a. RequestDispatcher
b. FilterChain
c. Cookie
d. Servletcontext
13. HTTP is stateless means:
a) each request is a new request
b) each user is a new user
c) each response is a new response
d) each request create a new session
14. What is a small piece of information that is persisted between the multiple client requests?
a. filter
b. Response
c. Cookie
d. session
15. What is an object that is invoked at the preprocessing and post processing of a request?
a. filter
b. Response
c. Cookie
d. session
16. An object of FilterConfig is created by --------
a. Web container
b. Deployment descriptor
c. Servlet
d. Filter
e. The Scriptlet
17. The scriptlet tag is :
a. <% code fragment %>
b. <%! Code fragment %>
c. <%= code fragement %>
d. <%-- This is JSP comment --%>
18. Which of the following is a server side technology?
a. html
b. jsp
c. javaScript
d. css
19. Which of the following is not a jsp directive?
a. include
b. page
c. scriptlet
d. useBean
20. What is difference between <%-- comment --%> and <!-- comment -->?
a. A - <%-- comment --%> is JSP comment. <!-- comment --> is an HTML comment.
b. B - <%-- comment --%> is ignored by JSP container.
2
c. C - <!-- comment --> is ignored by browser.
d. D - All of the above.
21. What is true about MIME type?
a. It tells the browser what type of data browser will send
b. It tells the browser what type of data browser will receive
c. It tells the server what type of data server will send
d. It tells the server what type of data server will receive

22. HTML is part of httprequest?


a. True
b. False

23. When we are sending data in URL in get method, how to separate parameters?
a. By comma
b. By semicolon
c. By question mark
d. By ampersand

24. Which http method send by browser that asks the server to get the page only?
a. Get
b. Post
c. Option
d. Put

25. Which of the following interprets html code and renders webpages to users?
a. Browser
b. Client
c. Server
d. None of the above

26. Which http method send by browser that gives the server what user data typed in the
form?
a. Put
b. Post
c. Delete
d. None of the above

27. How to send data in get method?


a. We cannot
b. Through URL
c. Through payload
d. None of the above

28. What is the nature of HTML page?


a. Dynamic
b. Static
c. Both dynamic and static
d. None of the above

3
29. Which tag does not belong to web.xml?
a. Web-app
b. Welcome-file-list
c. Servlet
d. Servlet-mappings

30. Who does control life-cycle of a servlet?


a. Browser
b. Client
c. Container
d. User
31. Which of the following interprets html code and renders webpages to user?
a. Client
b. server
c. browser
d. None of the above.
32. What is full form of MIME type?
a. Mail Interface Multiple Extension
b. Mail Internet Multiple Extension
c. Multiple Internet Mail Extension
d. Multiple Interface Mail Extension
33. When we are sending data in URL in get method, how to separate path and parameter?
a. By comma separator
b. By &
c. By ?
d. All of these
34. In which folder we can put web.xml?
a. class
b. package
c. WEB-INF
d. Webapps
35. Given an HttpServletRequest request and HttpServletResponse response, which sets a
cookie "username" with the value "joe" in a servlet?
(A) request.addCookie(new Cookie("username", "joe"));
(B) response.addCookie(new Cookie("username", "joe"));
(C) response.addCookie("username", "joe");
(D) request.addCookie("username", "joe");
36. Which two actions protect a resource file from direct HTTP access within a web
application? (Choose two.)
A. placing it in the /secure directory
B. placing it in the /WEB-INF directory
C. placing it in the /META-INF/secure directory
D. creating a element within the deployment descriptor
(A) A,C
(B) D,A
(C) B, C
(D) B,D

4
37. For a given ServletResponse response, which retrieve an object for writing text data?
(A) response.getOutputWriter()
(B) response.getWriter()
(C) response.getWriter().getOutputStream()
(D) response.getWriter(Writer.OUTPUT_TEXT)
38. Given:
1. public void service(ServletRequest request,
2. ServletResponse response) {
3. ServletInputStream sis =
4. // insert code here
5. }
Which retrieves the binary input stream on line 4 ?
(A) request.getReader();
(B) request.getWriter();
(C) request.getResourceAsStream();
(D) request.getInputStream();
39. Given the following servlet mapping definition for the web application named
'secureapp',
<servlet>
<servlet-name>ProcessLoginData</servlet-name>
<servlet-class>DoLogin</servlet-class>
<servlet/>
<servlet-mapping>
<servlet-name>ProcessLoginData</servlet-name>
<url-pattern>do/Login</url-pattern>
<servlet-mapping/>
Which of the following URLs will correctly request the Servlet?

(A) http://www.mywebapp.com/secureapp/do/Login?name="bob"
(B) http://www.mywebapp.com/secureapp/doLogin?name="bob"
(C) http://www.mywebapp.com/Login?name="bob"
(D) http://www.mywebapp.com/secureapp/Login?name="bob"
40. The method getWriter returns an object of type PrintWriter. This class has println
methods to generate output. Which of these classes define the getWriter method? Select
the one correct answer.
(A) HttpServletRequest
(B) ServletConfig
(C) HttpServletResponse
(D) ServletContext
41. Name the method defined in the HttpServletResponse class that may be used to set the
content type. Select the one correct answer.
(A) setContent
(B) setType
(C) setContentType
(D) setResponseContentType
Ques 14 :
42. In which file do we define a servlet mapping?
(A) servlet.mappings
(B) servlet.xml
(C) web.xml
5
(D) Simple.java
43. You are creating a servlet that generates stock market graphs. You want to provide the
web browser with precise information about the amount of data being sent in the
response stream.
Which HttpServletResponse methods will you use to provide this information?

(A) response.setLength(numberOfBytes);
(B) response.setContentLength(numberOfBytes);
(C) response.setHeader("Length", numberOfBytes);
(D) response.setIntHeader("Length", numberOfBytes);

44. You need to create a servlet filter that stores all request headers to a database for all
requests to the web application's home page "/index.jsp". Which HttpServletRequest
method allows you to retrieve all of the request headers?
(A) java.util.Iterator getRequestHeaders()
(B) java.util.Enumeration getHeaderNames()
(C) java.util.Iterator getHeaderNames()
(D) String[] getRequestHeaders()

45. Given an HttpSession session, a ServletRequest request, and a ServletContext context,


which retrieves a URL to /WEB-INF/myconfig.xml within a web application?
(A) request.getResource("/WEB-INF/myconfig.xml")
(B) session.getResource("/WEB-INF/myconfig.xml")
(C) getClass().getResource("/WEB-INF/myconfig.xml")
(D) context.getResource("/WEB-INF/myconfig.xml")

46. Which of the following code is used to get an attribute in a HTTP Session object in
servlets?
A. session.getAttribute(String name)
B. session.alterAttribute(String name)
C. session.updateAttribute(String name)
D. session.setAttribute(String name)
47. Which method is used to specify before any lines that uses the PintWriter?
A. setPageType()
B. setContextType()
C. setContentType()
D. setResponseType()
48. Which object of HttpSession can be used to view and manipulate information about a
session?
A. session identifier
B. creation time
C. last accessed time
D. All mentioned above
49. Which methods are used to bind the objects on HttpSession instance and get the objects?
A. setAttribute
B. getAttribute
C. Both A & B
D. None of the above
50. Which method take a string not a URL?

6
A. sendRedirect
B. forward
C. Both
D. None

You might also like