What is the role of the Content-Disposition header in file downloading?

  • Indicates the file size
  • Manages file encryption
  • Prompts for download
  • Specifies the file type
The Content-Disposition header plays a crucial role in file downloading by prompting the browser to download the file instead of displaying it. It specifies the disposition of the content, ensuring a proper download experience for users.

For a file upload, the request type must be __________.

  • FILE
  • GET
  • POST
  • UPLOAD
For a file upload, the request type must be POST.

To read uploaded files in a servlet, the __________ method is commonly used.

  • doGet()
  • doPost()
  • init()
  • service()
To read uploaded files in a servlet, the doPost() method is commonly used.

The response header __________ is crucial for indicating a file download rather than display.

  • Content-Type
  • File-Disposition
  • File-Type
  • Response-Content
The response header Content-Disposition is crucial for indicating a file download rather than display.

For secure file uploads, validating the __________ and __________ of the file is essential.

  • file name, content
  • file name, size
  • file type, content
  • file type, size
For secure file uploads, it's essential to validate both the file type and content to ensure the uploaded file is safe and meets the required criteria.

To handle multiple file uploads, a servlet may use the __________ API.

  • Java Authentication and Authorization Service (JAAS)
  • Java Naming and Directory Interface (JNDI)
  • JavaBeans Activation Framework (JAF)
  • JavaMail
To handle multiple file uploads, a servlet may use the JavaBeans Activation Framework (JAF) API to work with various types of data, including files.

A servlet is configured to allow only specific file types for upload. What strategies should be implemented to ensure this?

  • Rely on the web browser for file type validation
  • Use a third-party library for file type validation
  • Validate file types on the client side
  • Validate file types on the server side
Validating file types on the server side is a more secure approach to ensure that only specific file types are allowed for upload. Relying solely on client-side validation can be bypassed, so it's not recommended. Using a third-party library can also provide robust validation.

Describe a scenario where file download in a servlet might fail and how to address it.

  • Incomplete file on the server
  • Incorrect file path in the servlet configuration
  • Insufficient permissions to read the file
  • All of the above
Various factors such as an incomplete file on the server, an incorrect file path in the servlet configuration, or insufficient permissions can lead to file download failure. Addressing all these issues collectively (option 4) provides a comprehensive solution to potential download failures.

In a case where file uploads are taking too long, what are potential causes and solutions?

  • Large file size
  • Slow network connection
  • Insufficient server resources
  • All of the above
Potential causes for slow file uploads can include a large file size, a slow network connection, or insufficient server resources. Addressing all these factors collectively (option 4) can help optimize file upload performance.

What is the correct way to set a response header to prevent caching of servlet responses?

  • setCacheControl("no-cache")
  • setHeader("Cache-Control", "no-store")
  • setHeader("Expires", "0")
  • setHeader("Pragma", "no-cache")
The correct way to set a response header to prevent caching is by using setHeader("Cache-Control", "no-store"), which instructs the browser not to store the response in its cache.