Java Servlets and JSP Quiz
Test your knowledge of Java web development including servlets, JSP, HTTP methods, session management, and MVC pattern
Questions
Through a ServletContext object, servlets can interact with their enviornment.
- True
- False
To get an object of PrintWriter, we use getWriter() method of class _____________
- HttpSession
- HttpServletResponse
- HttpServletRequest
- None
A life-cycle method of a servlet is_________________
- init()
- service()
- destroy()
- Above All
Servlets are multi threaded
- True
- False
In the init(ServletConfig) method of Servlet life cycle, what method can be used to access the ServletConfig object ?
- getServletInfo()
- getInitParameters()
- getServletConfig()
- None
What JSP stand for
- Java Server Pages
- Java Server Programming
- Java Service Pages
- Java Service Programming
We must have configure and map all jsp files into web.xml
- True
- False
JSP can run by
- Apache Tomact
- Bea WebLogic
- Servlets
- JSP Engine
Syntax of Scriptlet Element
- <% code %>
- <@jsp code %>
- <jsp: scriptlet code />
- <%jsp code %>
Syntax of Declaration Element
- <%! code !%>
- <%! code %>
- <jsp: scriptlet code />
- <%jsp code !%>
Choose JavaBean Actions:-
- useBean
- setProperty
- getProperty
- All
Which of the following archive files can be deployed in a Web Server?
- jar
- war
- jar, war
- jar, war, ear
What are the support functions that the Container provide ____________?
- Communication Support
- Life-cycle Management
- Multithreading support
- All of the above
Which of the below statements are true considering MVC design pattern?
- Model – Java Class, JSP, View – HTML, Controller – Servlet
- Model – Java Class, View – JSP, Controller – Servlet
- Model – Java Class, View – JSP, Container – Servlet
- Model – Java Beans, View – JSP, HTML, Controller – Servlet, EJB
When you have non-idempotent request which Http method satisfy the requirement?
- GET
- POST
- PUT
- HEAD
Which of the following statements are true?
- HttpServletRequest getParameter(...) retrieves the parameter value from the request
- HttpServletResponse getAttribute(...) retrieves the attribute value from the response
- HttpServletResponse getParameter(...) retrieves the parameter value from the response
- HttpServletRequest setParameter(...) sets the parameter value to the request
Which method of HttpServletResponse is used to redirect an Http request to another URL?
- sendURL()
- redirectURL()
- sendRedirect()
- getRequestDispatcher()
What is the recommended way to deal with servlets and thread safety?
- Write servlet code to extend ThreadSafeServlet.
- Have the servlet implement SingleThreadModel
- Synchronize the service method of the servlet
- Use local variables exclusively, and if you have to use instance variables, synchronize access to them.
Which statements about HttpSession objects are true?
- A session whose timeout period has been set to -1 will never expire.
- A session will become invalid as soon as the user closes all the browser windows.
- A session will become invalid after a timeout period defined by the servlet container.
- A session may be explicitly invalidated by calling HttpSession.invalidateSession().
Which of the following statements are not true?
- URL rewriting may be used by a server as the basis for session tracking.
- SSL has a built-in mechanism that a servlet container could use to obtain data used to define a session.
- When using cookies for session tracking, the name of the session tacking cookie must be JSESSIONID.
- IF a user has cookies disabled in the browser, the container may choose to use a javax.servlet.httpCookielessHttpSession object to track the user's session.