Imp Questions AJP
Imp Questions AJP
Imp Questions AJP
Unit-5
1. What does the acronym "HTTP" stand for in the context of web communication?
A. Hyperlink Transfer Protocol B. Hypertext Transfer Protocol
C. Hyper Transfer Text Protocol D. High-Speed Text Protocol
2. In Java, which class is commonly used to establish a server socket for network
communication?
A. Socket B. ServerSocket C. DatagramSocket D. InetAddress
3. Which Java package provides classes for working with sockets and networking?
A. java.net B. java.io C. java.lang D. java.util
4. Which protocol is typically used for sending email in Java applications?
A. HTTP B. FTP C. SMTP D. POP3
5. Which Java class is used to represent an IP address?
A. IPAdress B. InetAddress C. IPHost D. HostAddress
6. What is the purpose of the "URLConnection" class in Java?
A. To represent a URL connection B. To establish a secure SSL connection
C. To handle HTTP requests and responses D. To encode and decode URLs
7. In Java, which protocol is used for transferring files over the network?
A. HTTP B. FTP C. TCP D. UDP
8. Which Java class is used to read and write binary data over a network stream?
A. BufferedReader B. BufferedWriter C. ObjectInputStream D.DataInputStream
9. What is the role of the "SocketTimeoutException" in Java networking?
A. It indicates a successful network connection.
B. It occurs when a socket is closed gracefully.
C. It signals a timeout when waiting for data on a socket.
D. It represents an error in the socket's IP address.
10. Which Java class allows you to create and manage URL objects?
A. URLBuilder B. URLManager C. URLEncoder D. URLConnection
Unit-6
1. What is a servlet in Java?
a) A type of coffee b) A server-side Java program c) A type of Java class d) A type
of Java exception
2. Which package provides the classes for servlets?
a) javax.servlet b) java.servlet c) javax.server d) java.server
3. Which HTTP methods can a servlet handle?
a) GET and POST b) GET, POST, PUT, and DELETE
c) GET, POST, and UPDATE d) GET, POST, DELETE, and MODIFY
4. In which method should you override to handle GET requests in a servlet?
a) doGet() b) doPost() c) doRequest() d) handleGet()
5. Which of the following is not a servlet life cycle method?
a) init() b) service() c) destroy() d) run()
6. What is the purpose of the `init()` method in a servlet?
a) To perform cleanup tasks before the servlet is destroyed b) To handle client
requests
c) To initialize the servlet before serving client requests d) To redirect requests
to other servlets
7. Which method is responsible for destroying a servlet?
a) finalize() b) destroy() c) close() d) cleanup()
8. What is the default scope of a servlet?
a) Request b) Session c) Application d) Page
9. Which object represents a client's request to the servlet container?
a) HttpServletRequest b) HttpServletResponse c) ServletContext d) HttpSession
10. Which method can be used to send a response to the client in a servlet?
a) getRequest() b) sendResponse() c) getResponse() d)
HttpServletResponse.getWriter()
11. How can you obtain the value of a request parameter in a servlet?
a) Using the `request.getAttribute()` method b) Using the `request.getParameter()`
method
c) Using the `request.getSession()` method d) Using the `request.getAttribute()`
method
12. What is the default URL mapping for a servlet in web.xml?
a) /servlet/* b) /servlets/* c) /app/* d) /servlet-name/*
13. What is the purpose of the `web.xml` file in a servlet application?
a) To configure servlet mappings b) To define servlet classes
c) To specify HTML templates d) To store database connection details
14. Which HTTP status code indicates that a resource is not found?
a) 200 OK b) 302 Found c) 404 Not Found d) 500 Internal Server Error
/ 63
15. Which interface must a servlet implement to handle session events?
a) HttpSessionListener b) HttpSessionAttributeListener
c) ServletContextListener d) ServletRequestListener
16. How can you store session data in a servlet?
a) Using the `HttpServletRequest` object b) Using the `ServletContext` object
c) Using the `HttpSession` object d) Using the `HttpServletResponse` object
17. What is the purpose of the `ServletContext` in a servlet application?
a) To store session data b) To manage the servlet life cycle
c) To share data among servlets d) To store servlet configuration parameters
18. How can you set an attribute in the `ServletContext` in a servlet?
a) Using the `setContextAttribute()` method b) Using the `setAttribute()` method
c) Using the `addAttribute()` method d) Using the `context.set()` method
19. What is the purpose of the `RequestDispatcher` interface in servlets?
a) To send an HTTP request to another server
b) To include the content of another resource in the response
c) To forward the request to another resource within the same servlet context
d) To send a response to the client
20. Which of the following is NOT a valid way to create a servlet in Java?
a) Extending the `HttpServlet` class b) Implementing the `Servlet` interface
c) Using the `new` keyword d) Extending the `GenericServlet` class
21. What is a servlet filter used for?
a) To process requests before they reach a servlet b) To filter out invalid HTTP
methods
c) To filter out client IP addresses d) To filter out invalid session data
22. Which of the following is true about servlet filters?
a) Filters can only be used with servlets and not with JSP.
b) Filters can modify the response but not the request.
c) Filters cannot change the order of execution of servlets.
d) Filters can be configured in the web.xml file.
23. What is the purpose of the `doFilter()` method in a servlet filter?
a) To forward the request to another servlet b) To send a response to the client
c) To process the request and response d) To destroy the filter
24. How can you invalidate a session in a servlet?
a) session.invalidate() b) session.invalidateSession() c) session.destroy() d)
session.remove()
25. Which of the following is NOT a valid method of communication between servlets?
a) Using the `ServletContext` b) Using the `HttpServletResponse`
c) Using the `RequestDispatcher` d) Using HTTP sessions
26. What is the purpose of the `javax.servlet.annotation.WebServlet` annotation?
a) To define a servlet class b) To configure servlet mappings c) To specify request
parameters d) To declare a servlet filter
27. Which HTTP method is used to retrieve data from the server in a safe and
idempotent way?
a) GET b) POST c) PUT d) DELETE
28. Which method is called when a session is created in a servlet?
a) sessionCreated() b) sessionInitialized() c) initSession() d) createSession()
29. How can you obtain the session ID in a servlet? a)
session.getSessionID() b) session.getID() c) session.getId() d)
session.getSessionId()
30. What is the purpose of the `ServletContext.getAttribute()` method?
a) To retrieve a session attribute b) To retrieve a request attribute
c) To retrieve a servlet context attribute d) To retrieve a response attribute
31. What is the purpose of the `HttpServletRequest.setAttribute()` method?
a) To set a session attribute b) To set a request attribute
c) To set a servlet context attribute d) To set a response attribute
32. Which of the following is NOT a valid HTTP status code?
a) 200 OK b) 300 Redirect c) 400 Bad Request d) 500 Internal Server Error
33. What is the purpose of the `ServletContext.getInitParameter()` method?
a) To retrieve a servlet's initialization parameter b) To retrieve a session
attribute
c) To retrieve a request attribute d) To retrieve a servlet context attribute
34. What is the purpose of the `HttpServletResponse.setContentType()` method?
a) To set the HTTP response status code b) To set the content length of the
response
c) To set the content type of the response d) To send a redirect response
35. Which of the following is NOT a valid content type for an HTTP response?
a) text/html b) application/json c) image/png d) audio/mp3
36. What is the purpose of the `ServletContext.getContextPath()` method?
a) To retrieve the context path of a servlet b) To retrieve the context path of a
session
c) To retrieve the context path of a request d) To retrieve the context path of the
servlet container
40. What is the purpose of the `HttpServletResponse.setStatus()` method?
a) To set the HTTP response status code b) To set the content type of the response
c) To set the character encoding of the response d) To set the content length of
the response