The deployment descriptor file used to configure a servlet in a web application is named __________.
- servlet-config.xml
- web-app.xml
- web-config.xml
- web.xml
The deployment descriptor file used to configure a servlet in a web application is named web.xml.
What is the significance of the path attribute in a cookie?
- It defines the cookie's value
- It indicates the cookie's path
- It sets the cookie's domain
- It specifies the cookie's name
The path attribute in a cookie is significant as it indicates the URL path for which the cookie is valid. The client sends the cookie only if the path matches the requested URL.
In what scenario is it more appropriate to use RequestDispatcher over HttpServletResponse's sendRedirect?
- When maintaining the original URL is crucial
- When preserving client-side state is necessary
- When the resource is on a different server
- When the resource is on the same server
RequestDispatcher is more appropriate when you need to forward a request internally within the server, maintaining the original URL. This is especially important when you want to keep the original URL in the browser's address bar.
How does the servlet container handle HTTP headers when using RequestDispatcher's forward method?
- HTTP headers are discarded
- HTTP headers are duplicated
- HTTP headers are modified
- HTTP headers are preserved
When using RequestDispatcher's forward method, the servlet container discards the original response headers, allowing the forwarded resource to generate a new set of headers. This is important to avoid conflicts and ensure that the forwarded resource has control over the headers.
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.
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).