![]() |
In this interview preparation blog post, we will cover some commonly asked Struts interview questions and provide an in-depth overview of Struts, covering its key concepts, architecture, features, and advantages to help you ace your next interview. Whether you are a beginner looking to break into the field or a professional developer wanting to sharpen your skills, preparing for Struts interview questions is essential. Let’s dive in and get you ready for success! Basically, Struts is a powerful framework used in Java web development, offering a structured approach to building web applications. Understanding Struts is crucial for Java developers aiming to excel in web development interviews, and mastering it can open up new opportunities in your career. So to help you and make you more confident, we have compiled a list of common Struts interview questions for beginners and professionals. ![]() Table of Content Basic Struts Interview Questions for FreshersLooking to kick-start their Struts journey can benefit from mastering these fundamental interview questions. Covering topics such as Struts architecture, action classes, and form handling, these questions will help you build a solid foundation in the framework. 1. What is Struts?Struts Framework is an open-source and easy tool to build Java Enterprise Edition (Java EE) web applications using Struts.
2. What are the key components of the Struts framework?The components of the Struts framework are listed below:
3. What are the features of Struts?There are so many features of Struts. Some of them are listed below:
4. What are the core classes of a Struts application?
5. What is MVC architecture in the Struts framework?MVC is an architectural design pattern. It stands for Model, View, and Controller.
6. What is an Interceptor and what are its lifecycle methods?Interceptor is an object and it is used to be invoked during the preprocessing and postprocessing of a request. It performs exception handling, validation, internationalization, and also it is pluggable. The lifecycle methods of interceptors are:
7. What is the Flow of Requests in Struts-based applications?The Struts-based application follows MVC architecture. The flow of the requests in Struts explained below: ![]()
8. Differentiate between Struts 1 and Struts 2.
9. What is the role of the Action class in the Struts framework?In Struts, the Action class acts as a Controller component and it is responsible for processing the requests of users. It performs the following roles:
Struts Interview Questions for IntermediateIntermediate Struts developers can improve their skills by answering these advanced interview questions. These questions will test your knowledge and prepare you for senior-level positions, covering topics such as Struts setup, tile configuration, and custom tag libraries, as well as more complicated scenarios such as handling exceptions and constructing custom validators. 10. What is ActionForm in Struts and how it is created?ActionForm in Struts is a JavaBean class. It acts as a container and transfers data between the presentation layer i.e. the HTML forms and the business logic layer i.e. the Action classes. It represents a collection of data from an HTML form and it provides getters and setters to get this data. To create an ActionForm in Struts:
11. What is the struts-default package?In the Struts configuration, the struts-default package is a pre-defined default package. It contains all the default configurations and features that are commonly used in the Struts applications. This default package provides necessary frameworks and packages and by using them, we can build web applications quickly without having to configure everything from scratch. This package typically include default configuration for interceptors, result types, and error handling, commonly used utility classes, and resources such as CSS files or JavaScript libraries. Developers can use these defaults as it is or can customize them according to the specific application requirements. 12. What is ForwardAction in Struts?In Struts, the ForwardAction class is used to forward total control from one location to another within the Struts application like from a JSP to a local server.
13. How action-mapping tag is used for request forwarding in Struts configuration file?Under action-mapping tag, forwarding options are defined in Struts configuration file i.e. struts-config.xml.
In the below example, if we click on the hyperlink, request will be forwarded to /pages/login.jsp using the below configuration from struts configuration file: <action-mappings>
<action path="/login" forward="/pages/welcome.jsp">
</action>
</action-mappings>
14. How can Validation Errors be displayed on a JSP page?To display all Validation errors to user on JSP page based on the validation rules defined in validation.xml file, we can use Struts tags such as <html:errors> or <html:errors/> in JSP file. During form validation, these tags are used to display automatically generated error messages. 15. How duplicate form submission can be controlled in Struts?To control duplicate form submission, we can use Token Interceptor provided by Struts.
16. How can we access Java Beans and their properties in Struts?To access Java Beans and their properties, we can use Bean Tag Library in Struts. This is a library which can be used to access Java beans. 17. What are the two types of Validations supported by Validator Framework in Struts?For form data validation, Validator framework is used. The Validator framework provides two types of validation:
Struts Interview Questions for ExperiencedIn this section we have covered advanced topics such as Struts 2.x, Struts configuration with XML, and custom plugin development, these questions will push your knowledge to its limits and prepare you for leadership roles. 18. What is DynaActionForm?DynaActionForm is a sub-class of ActionForm Class. It is used to dynamically create form beans. For form bean creation, it uses configuration files. It dynamically handles the form data without the need to create a separate form bean class for each HTML form. 19. What are ActionServlets and Why ActionServlet singleton in Struts?In Struts, the ActionServlets are the central controller components and it manages the entire request handling process in the application. ActionServlet is singleton in Struts.
20. What is the role of the Struts configuration file (struts-config.xml)?Struts Configuration file i.e. struts-config.xml only serves as a central configuration file for the Struts applications.
Refer the below sample struts-config.xml file for better understanding. <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<!-- Define action mappings -->
<action-mappings>
<!-- Define mappings between URLs and action classes -->
</action-mappings>
<!-- Define global settings such as form beans and message resources -->
</struts-config>
21. What is meant by the validate() and reset() function in Struts?
22. What are the condition for actionForm to work correctly?ActionForm should follow the following conditions to work correctly.
23. What are OGNL and ValueStack in Struts?OGNL stands for Object Graph Navigation Language. It is an expression language of Struts2. ValueStack is a stack and it contains all values and action specific object with data linked to actions. The values or data of ValueStack are changed through OGNL library. For more details please refer to this article: Struts 2 OGNL 24. How Client side validation is enables on a JSP form?To enable client-side validation in Struts, we need to enable the validator plug-in inside the struts configuration file i.e. struts-config.xml. By adding the below configurations in struts-config.xml file, this process can be done. <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathname"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
Now, the validation rules are defined in validation.xml file. Let’s see a simple example, if a form contains email field, and we want to do client side validation on email field, following code will be added in validation.xml file: <form name="gfgForm">
<field property="email"
depends="required">
<arg key="gfgForm.email"/>
25. What is declarative exception handling in Struts?
ConclusionIn this free interview preparation guide, we have covered a wide range of Struts interview questions and answers to help you excel in your next interview. From basic concepts to advanced topics, these questions have been carefully selected to assess your knowledge and understanding of the Struts framework. |
Reffered: https://www.geeksforgeeks.org
Advance Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |