Master Java web development with these 30 MCQs focused on Java Servlets and JSP. These questions cover the core concepts of Servlets, JSP Architecture, Session Management, and communication between Servlets and JSP.
java.netjavax.servletjava.sqljava.iodoPost()doGet()handleRequest()execute()service() method in a servlet?
<% %><!DOCTYPE><jsp:script><java>.jsp.java.html.jsgetSession()getSession(true)createSession()getRequest()HttpServletRequestHttpSessionServletConfigServletContextsession.invalidate()session.close()session.terminate()session.end()web.xml file?
<session-timeout><timeout-session><session><time-out>Set-CookieAuthorizationLocationContent-TypeHttpServletRequest.getSession() method?
RequestDispatcher.forward()JSP.forward()response.sendRedirect()RequestDispatcher.sendRedirect()<jsp:include> tag do in a JSP page?
request.setAttribute()response.sendRedirect()<jsp:forward><jsp:include><jsp:redirect><jsp:route>request.getRequestDispatcher("page.jsp").forward()response.sendRedirect("page.jsp")response.forward("page.jsp")request.sendRedirect("page.jsp")response.sendRedirect() method in servlets?
RequestDispatcher.forward() method in servlets?
response.sendRedirect()<jsp:include> tagRequestDispatcher.forward()ServletContext.include()| Qno | Answer |
|---|---|
| 1 | b) A class that handles HTTP requests |
| 2 | b) javax.servlet |
| 3 | b) doGet() |
| 4 | c) To handle HTTP requests and send a response |
| 5 | b) It is created once and can handle multiple requests |
| 6 | b) Java Server Pages |
| 7 | a) <% %> |
| 8 | b) JSP separates HTML and Java code |
| 9 | a) .jsp |
| 10 | b) JSP Container |
| 11 | b) Tracking user interactions across requests |
| 12 | b) By a session ID stored in a cookie |
| 13 | b) getSession(true) |
| 14 | a) 30 minutes |
| 15 | b) HttpSession |
| 16 | a) session.invalidate() |
| 17 | a) <session-timeout> |
| 18 | a) Set-Cookie |
| 19 | a) To get the current session object |
| 20 | c) Session scope |
| 21 | a) RequestDispatcher.forward() |
| 22 | b) It includes another JSP page at runtime |
| 23 | d) All of the above |
| 24 | a) <jsp:forward> |
| 25 | b) The request and response objects are passed to the JSP |
| 26 | b) response.sendRedirect("page.jsp") |
| 27 | d) All of the above |
| 28 | b) To redirect the client to a new URL |
| 29 | c) It forwards the request and response within the same web application |
| 30 | b) <jsp:include> tag |