How are requests forwarded from servlets to the appropriate view in an MVC framework?

  • Forward
  • Include
  • Redirect
  • Response.sendRedirect()
Requests from servlets to the appropriate view in an MVC framework are forwarded using the Forward mechanism, allowing seamless interaction between the controller and the view components.

What role do servlets play in handling controller logic in MVC frameworks?

  • Servlets are responsible for rendering views in MVC frameworks.
  • Servlets handle the controller logic by processing and managing user requests.
  • Servlets manage database connections in MVC architectures.
  • Servlets primarily focus on handling presentation logic in MVC.
Servlets play a crucial role in handling controller logic by processing and managing user requests, directing them to the appropriate components in the MVC architecture.

In MVC architecture, how does a servlet interact with the model to process business logic?

  • Servlets communicate with the model through JavaBeans or other business logic components.
  • Servlets directly manipulate the model by interacting with the database.
  • Servlets have no interaction with the model in MVC.
  • Servlets use JSPs exclusively to handle business logic in MVC.
Servlets interact with the model by communicating through JavaBeans or other dedicated business logic components to process business logic in an MVC application.

How do you set a response header to indicate the content should be downloaded as a file?

  • response.setHeader("Content-Disposition", "attachment; filename=example.txt");
  • response.setHeader("Content-Encoding", "gzip");
  • response.setHeader("Content-Transfer-Encoding", "binary");
  • response.setHeader("Content-Type", "application/octet-stream");
To indicate that the content should be downloaded as a file, you can use the response.setHeader("Content-Disposition", "attachment; filename=example.txt"); method.

In the context of XSS prevention, what does the acronym CSP stand for?

  • Content-Security-Policy
  • Content-Security-Protocol
  • Cookie-Security-Protocol
  • Cross-Site Policy
In the context of XSS prevention, CSP stands for Content-Security-Policy. It is a security header that helps prevent XSS attacks by specifying which content can be executed on a web page.

Which JavaScript framework automatically escapes output to prevent XSS attacks?

  • AngularJS
  • React
  • Vue.js
  • jQuery
AngularJS automatically escapes output to prevent XSS attacks by default, helping developers build more secure web applications.

How does a Content Security Policy (CSP) help in preventing XSS attacks?

  • It allows only inline scripts
  • It encrypts the communication
  • It filters HTTP headers
  • It restricts the sources of content
A Content Security Policy (CSP) helps prevent XSS attacks by restricting the sources of content, reducing the risk of malicious script execution from unauthorized sources.

To maintain a separation of concerns, servlets in MVC should not directly manipulate the __________.

  • Controller
  • Database
  • Model
  • View
To maintain a separation of concerns, servlets in MVC should not directly manipulate the Controller.

The __________ method in servlets is often used to dispatch requests to different handlers in an MVC framework.

  • doDispatch()
  • doPost()
  • init()
  • service()
The doDispatch() method in servlets is often used to dispatch requests to different handlers in an MVC framework.

In a complex web application using MVC and servlets, a new feature requires integration of a third-party service. Where should this integration primarily take place?

  • In a separate utility class
  • In the Controller
  • In the Model
  • In the View
In MVC architecture, business logic, including third-party service integration, is primarily handled in the Controller. This ensures separation of concerns and makes the application more modular.