To set the content type of the response in a servlet, which method is commonly used?
- addType(String type)
- appendContentType(String type)
- setContentType(String type)
- writeType(String type)
The setContentType(String type) method is commonly used to set the content type of the response in a servlet.
How are servlet mappings defined in the web application deployment descriptor?
Servlet mappings are defined using the element in the web application deployment descriptor (web.xml).
Servlet configuration parameters are accessed via the _________ method of the ServletConfig interface.
- getInitParameter()
- getParamValue()
- getParameter()
- readConfigParameter()
Servlet configuration parameters are accessed using the getInitParameter() method of the ServletConfig interface.
When integrating with Java-based frameworks like Spring, which technology provides more seamless integration?
- Both
- JSP
- None of the above
- Servlet
When integrating with Java-based frameworks like Spring, Servlets provide more seamless integration. Servlets are the foundation of Java web applications, and frameworks like Spring often use Servlets as a basis for handling requests and managing the application flow. Integrating with Servlets is a common practice in Spring-based applications.
How do you retrieve form data sent through a GET request in a servlet?
- request.getFormData()
- request.getParameter()
- request.readFormData()
- request.readParameter()
The request.getParameter() method is used to retrieve form data sent through a GET request in a servlet.
The _________ method of a servlet is called once, indicating that the servlet is being placed into service.
- destroy()
- doGet()
- init()
- service()
The init() method of a servlet is called once, indicating that the servlet is being placed into service for initialization purposes.
What method is commonly used to send a redirect response to the client in servlets?
- forwardResponse()
- redirectResponse()
- sendForward()
- sendRedirect()
The sendRedirect() method is commonly used in servlets to send a redirect response to the client, specifying the new URL to which the client should be redirected.
Which of the following is a Java class that extends the capabilities of the servers?
- Applet
- JSP
- JavaBean
- Servlet
A Servlet is a Java class that extends the capabilities of servers, providing a way to generate dynamic content on the web.
What is the maximum size of data that can be sent using the GET method in a servlet?
- 2 GB
- 256 KB
- Limited by server configuration
- No specific limit
There is no specific limit imposed by the HTTP specification on the size of data that can be sent using the GET method. However, practical limitations may exist, and server configurations can impose their own limits.
A servlet needs to send a file to the client with a specific filename. Which response header should be set and by which method?
- Cache-Control, setHeader()
- Content-Disposition, setHeader()
- Content-Type, setContentType()
- Location, sendRedirect()
To send a file with a specific filename, the Content-Disposition header should be set using the setHeader() method in the HttpServletResponse.