Web Technologies MCQs

  1. Which of the following is true about Servlets?
    a) Java classes that handle HTTP requests
    b) Run on servlet containers like Tomcat
    c) Provide lifecycle methods init(), service(), destroy()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  2. What will be printed?
    1 import javax.servlet.*;
    2 import javax.servlet.http.*;
    3 public class EduinqServlet extends HttpServlet {
    4 protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    5 System.out.println("Eduinq Servlet GET");
    6 }
    7 }
    a) Eduinq Servlet GET
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Servlet GET

  3. Which of the following is true about JSP?
    a) Java Server Pages
    b) Allow embedding Java in HTML
    c) Compiled into Servlets
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  4. What will be printed?
    1 <%@ page language="java" %>
    2 <html>
    3 <body>
    4 <%= "Eduinq JSP" %>
    5 </body>
    6 </html>
    a) Eduinq JSP
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq JSP

  5. Which of the following is true about JSP implicit objects?
    a) request, response, session, application
    b) out, config, pageContext
    c) page, exception
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  6. Which of the following is true about Filters in Servlets?
    a) Intercept requests and responses
    b) Used for logging, authentication, compression
    c) Implement javax.servlet.Filter
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  7. What will be printed?
    1 import javax.servlet.*;
    2 public class EduinqFilter implements Filter {
    3 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
    4 System.out.println("Eduinq Filter Applied");
    5 }
    6 }
    a) Eduinq Filter Applied
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Filter Applied

  8. Which of the following is true about Session Management?
    a) Maintains state across requests
    b) Uses cookies or URL rewriting
    c) HttpSession provides methods like setAttribute()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  9. What will be printed?
    1 HttpSession session = request.getSession();
    2 session.setAttribute("eduinq","Portal");
    3 System.out.println(session.getAttribute("eduinq"));
    a) Portal
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Portal

  10. Which of the following is true about ServletContext?
    a) Provides application wide information
    b) Shared among all servlets
    c) Allows init parameters
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  11. Which of the following is true about RESTful Web Services?
    a) Use HTTP methods for CRUD
    b) Stateless communication
    c) Return JSON/XML
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  12. What will be printed?
    1 import javax.ws.rs.*;
    2 @Path("/eduinq")
    3 public class EduinqRest {
    4 @GET
    5 @Produces("text/plain")
    6 public String getMsg() {
    7 return "Eduinq REST Service";
    8 }
    9 }
    a) Eduinq REST Service
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq REST Service

  13. Which of the following is true about ServletConfig?
    a) Provides servlet specific configuration
    b) Access init parameters
    c) Available via getServletConfig()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  14. Which of the following is true about JSP directives?
    a) page, include, taglib
    b) Control overall structure of JSP
    c) Declared with <%@ %>
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  15. Which of the following is true about JSP actions?
    a) Use XML syntax
    b) Include jsp:include, jsp:forward
    c) Provide dynamic behavior
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  16. Which of the following is true about MVC architecture in web apps?
    a) Model handles data
    b) View handles presentation
    c) Controller handles logic
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  17. Which of the following is true about Servlet lifecycle?
    a) init() called once
    b) service() called per request
    c) destroy() called on shutdown
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  18. Which of the following is true about JSP lifecycle?
    a) Translation, compilation, initialization
    b) Execution, destruction
    c) Managed by container
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  19. Which of the following is true about REST design principles?
    a) Statelessness
    b) Resource identification via URIs
    c) Uniform interface
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  20. Which of the following is true about Filters chaining?
    a) Multiple filters can be applied
    b) Order defined in web.xml
    c) Each filter calls chain.doFilter()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  21. Which of the following is true about HttpSession invalidation?
    a) Ends the session immediately
    b) Removes all attributes
    c) Called using invalidate()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  22. What will be printed?
    1 HttpSession session = request.getSession();
    2 session.setAttribute("eduinq","Portal");
    3 session.invalidate();
    4 System.out.println(session.getAttribute("eduinq"));
    a) null
    b) Portal
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — null

  23. Which of the following is true about session timeout?
    a) Configured in web.xml
    b) Default is 30 minutes
    c) Can be set programmatically with setMaxInactiveInterval()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  24. Which of the following is true about JSP Expression Language (EL)?
    a) Simplifies access to data
    b) Syntax like ${attribute}
    c) Resolves attributes from scopes (page, request, session, application)
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  25. What will be printed?
    1 <%
    2 request.setAttribute("eduinq","Portal");
    3 %>
    4 ${eduinq}
    a) Portal
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Portal

  26. Which of the following is true about JSTL?
    a) JSP Standard Tag Library
    b) Provides core, fmt, sql, xml tags
    c) Simplifies JSP development
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  27. What will be printed?
    1 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    2 <c:set var="eduinq" value="Portal"/>
    3 <c:out value="${eduinq}"/>
    a) Portal
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Portal

  28. Which of the following is true about @PathParam in REST?
    a) Extracts values from URI path
    b) Used in JAX RS methods
    c) Annotated parameter matches URI template
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  29. What will be printed?
    1 import javax.ws.rs.*;
    2 @Path("/eduinq")
    3 public class EduinqRest {
    4 @GET
    5 @Path("/{name}")
    6 public String getMsg(@PathParam("name") String name) {
    7 return "Eduinq " + name;
    8 }
    9 }
    a) Eduinq Portal (if /eduinq/Portal called)
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Portal (if /eduinq/Portal called)

  30. Which of the following is true about @QueryParam in REST?
    a) Extracts query parameters from URL
    b) Used in JAX RS methods
    c) Annotated parameter matches query string
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  31. What will be printed?
    1 import javax.ws.rs.*;
    2 @Path("/eduinq")
    3 public class EduinqRest {
    4 @GET
    5 public String getMsg(@QueryParam("id") String id) {
    6 return "Eduinq ID " + id;
    7 }
    8 }
    a) Eduinq ID 10 (if /eduinq?id=10 called)
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq ID 10 (if /eduinq?id=10 called)

  32. Which of the following is true about JSON marshalling in REST?
    a) Converts Java objects to JSON
    b) Uses libraries like Jackson
    c) Automatic with @Produces("application/json")
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  33. Which of the following is true about XML marshalling in REST?
    a) Converts Java objects to XML
    b) Uses JAXB annotations
    c) Automatic with @Produces("application/xml")
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  34. Which of the following is true about Authentication Filters?
    a) Intercept requests for authentication
    b) Implement javax.servlet.Filter
    c) Can check headers or tokens
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  35. Which of the following is true about Servlet Listeners?
    a) Monitor events in web app
    b) Include ServletContextListener, HttpSessionListener
    c) Useful for resource initialization and cleanup
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  36. Which of the following is true about HttpSessionListener?
    a) Monitors session creation and destruction
    b) Provides sessionCreated() and sessionDestroyed()
    c) Useful for tracking active users
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  37. Which of the following is true about debugging JSP?
    a) Check generated servlet code
    b) Use logging statements
    c) Validate EL and JSTL usage
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  38. Which of the following is true about ServletException?
    a) Indicates servlet related errors
    b) Checked exception
    c) Can wrap other exceptions
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  39. Which of the following is true about RequestDispatcher?
    a) Forwards request to another resource
    b) Includes content of another resource
    c) Obtained via getRequestDispatcher()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  40. What will be printed?
    1 RequestDispatcher rd = request.getRequestDispatcher("eduinq.jsp");
    2 rd.include(request,response);
    3 System.out.println("Eduinq Include Done");
    a) Eduinq Include Done
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Include Done

  41. Which of the following is true about Servlet forward vs include?
    a) Forward transfers control, include adds output
    b) Forward does not return to caller
    c) Include returns to caller after execution
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  42. Which of the following is true about JSP error handling?
    a) Use errorPage directive
    b) Define isErrorPage attribute
    c) Can configure in web.xml
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  43. Which of the following is true about web.xml deployment descriptor?
    a) Defines servlet mappings
    b) Configures filters, listeners
    c) Provides init parameters
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  44. Which of the following is true about annotations replacing web.xml?
    a) @WebServlet, @WebFilter, @WebListener
    b) Simplify configuration
    c) Supported in Servlet 3.0+
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  45. Which of the following is true about REST response codes?
    a) 200 OK for success
    b) 404 Not Found for missing resource
    c) 500 Internal Server Error for server issues
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  46. Which of the following is true about REST content negotiation?
    a) Client specifies Accept header
    b) Server selects appropriate representation
    c) Supports JSON, XML, etc.
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  47. Which of the following is true about Servlet security constraints?
    a) Defined in web.xml
    b) Restrict access to resources
    c) Can specify roles
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  48. Which of the following is true about JSP EL operators?
    a) Include arithmetic, relational, logical
    b) Syntax like ${a+b}
    c) Simplify expressions
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  49. Which of the following is true about REST statelessness?
    a) Each request independent
    b) No server side session state
    c) Improves scalability
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  50. Which of the following is true about REST best practices?
    a) Use nouns for resources
    b) Use proper HTTP methods (GET, POST, PUT, DELETE)
    c) Provide meaningful status codes
    d) All of the above
    View Answer

    Correct answer: D — All of the above

Quick Links to Explore