Learn J2EE MCQs

Prepare J2EE MCQs (Multiple choice Questions) for exam and job interviews.

What is the purpose of `HttpServletResponse.sendRedirect()`?

1) Redirects the client to a new URL

2) Forwards the request to another resource

3) Includes content from another resource

4) Closes the current session

Answer : Redirects the client to a new URL

Which of the following is a built-in J2EE listener?

1) HttpSessionListener

2) ServletListener

3) ApplicationListener

4) RequestListener

Answer : HttpSessionListener

Which of the following is true about the `RequestDispatcher.forward()` method?

1) It forwards the request to another resource within the same server

2) It redirects the client to a new URL

3) It sends an error response to the client

4) It closes the session

Answer : It forwards the request to another resource within the same server

Which of the following is NOT a valid session tracking method?

1) Cookies

2) Hidden form fields

3) URL rewriting

4) HTML5 session storage

Answer : HTML5 session storage

What is the main purpose of `ServletFilter`?

1) It intercepts and processes requests before they reach a servlet

2) It initializes servlet configurations

3) It manages session state

4) It forwards requests to another servlet

Answer : It intercepts and processes requests before they reach a servlet

Which method in a servlet is called when an HTTP POST request is made?

1) doPost()

2) doGet()

3) service()

4) init()

Answer : doPost()

What is the default content type for a servlet response?

1) text/html

2) application/xml

3) text/plain

4) application/json

Answer : text/html

Which of the following is NOT true about `HttpSession`?

1) It is specific to a user

2) It is shared across all users

3) It stores data on the server

4) It can have an expiration time

Answer : It is shared across all users

What is the default scope of a JSP directive?

1) page

2) request

3) session

4) application

Answer : page

Which HTTP status code represents a successful request?

1) 200 OK

2) 404 Not Found

3) 500 Internal Server Error

4) 301 Moved Permanently

Answer : 200 OK