Struts Interview Questions and Answers for 2 years experience

Struts Interview Questions and Answers (2 years experience)
  1. What is Struts?

    • Answer: Struts is a free, open-source framework for creating Java web applications based on the MVC (Model-View-Controller) architectural pattern. It simplifies the development process by providing reusable components and a structured approach to building web applications.
  2. Explain the MVC architecture in Struts.

    • Answer: In Struts, the Model represents the business logic and data, the View is responsible for presenting the data to the user (typically JSP pages), and the Controller (Struts' ActionServlet or FilterDispatcher) manages the flow of the application, handling user requests and selecting the appropriate View.
  3. What are the core components of Struts?

    • Answer: The core components include ActionServlet/FilterDispatcher, Actions, ActionForms, ActionMappings, Interceptors, and JSPs (or other view technologies).
  4. What is the role of ActionServlet/FilterDispatcher?

    • Answer: ActionServlet (in Struts 1) or FilterDispatcher (in Struts 2) acts as the central controller. It intercepts incoming requests, determines which Action to execute based on the request URL, and then forwards the request to the appropriate Action.
  5. What is an Action class in Struts?

    • Answer: An Action class is a Java class that encapsulates the business logic for a specific user request. It receives the request parameters from the ActionForm, processes the data (often interacting with the Model), and returns an ActionForward object to specify the next view to be displayed.
  6. What is an ActionForm in Struts?

    • Answer: An ActionForm is a JavaBean that holds the data submitted by the user through an HTML form. Struts automatically populates the ActionForm with the request parameters. It provides data validation capabilities.
  7. What is ActionMapping?

    • Answer: ActionMapping is a configuration element in the struts-config.xml (Struts 1) or struts.xml (Struts 2) file that maps a request path to a specific Action class. It defines the path, the Action class, and the input and success forward paths.
  8. Explain Struts Tiles.

    • Answer: Struts Tiles is a templating framework that allows developers to create reusable page components (tiles) and assemble them into complete pages. This promotes code reusability and simplifies page layout management.
  9. What are Interceptors in Struts 2?

    • Answer: Interceptors are pluggable components that intercept the request processing flow in Struts 2. They can perform various tasks such as authentication, authorization, logging, and data validation before or after the Action is executed.
  10. What is the difference between Struts 1 and Struts 2?

    • Answer: Struts 2 is a significant improvement over Struts 1. Key differences include the use of a more flexible plugin architecture (vs. a tightly coupled framework), the use of POJOs (Plain Old Java Objects) for Actions, the use of OGNL (Object-Graph Navigation Language) for data access, and a much improved interceptor mechanism. Struts 2 is generally considered to be more lightweight and easier to use.
  11. How does data validation work in Struts?

    • Answer: In Struts 1, validation is often done within the ActionForm using validate() method. Struts 2 provides more flexible validation mechanisms using annotations or XML configuration, typically leveraging validation frameworks like XWork or custom validators.
  12. How do you handle exceptions in Struts?

    • Answer: Exceptions can be handled using exception handlers or by implementing custom exception handling logic within the Actions. Struts 2 provides exception mappings in the struts.xml file to specify which view to display when a specific exception occurs.
  13. Explain the concept of ActionForward in Struts 1.

    • Answer: In Struts 1, ActionForward represents the destination of the request after the Action is executed. It specifies the path to the next view (JSP page) or another Action.
  14. What are ValueStack and OGNL in Struts 2?

    • Answer: The ValueStack is a data structure in Struts 2 that stores the data required by the View. OGNL (Object-Graph Navigation Language) is an expression language used to access data stored in the ValueStack from within JSPs or other view technologies.
  15. How do you configure Struts in a web application?

    • Answer: Configuration involves adding necessary JAR files to the classpath, configuring the web.xml to include the Struts filter/servlet, and creating a configuration file (struts-config.xml or struts.xml) to define Action mappings, ActionForms, and other settings.
  16. Explain the use of result types in Struts 2.

    • Answer: Result types define how the response is sent back to the client. Common result types include JSP, redirect, JSON, free marker, etc., and determine how the action result is rendered.
  17. How to implement file upload in Struts 2?

    • Answer: File uploads are handled using the `@Parent` annotation or a custom interceptor in Struts 2. The uploaded file is accessed via the properties of an Action class.

Thank you for reading our blog post on 'Struts Interview Questions and Answers for 2 years experience'.We hope you found it informative and useful.Stay tuned for more insightful content!