Struts Interview Questions for Experienced

In 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.

  • When the request received, it routed to the corresponding Action classes based on configured mappings.
  • It call to the process() method of RequestProcessor.
  • It handles the overall flow of control within the application.
  • ActionServlet is based on singleton design pattern because only one object needs to be created for this controller class and for each user’s request multiple threads are created later.

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.

  • It maps the incoming requests URLs with appropriate Action classes.
  • Mapping is done along with the global settings such as message resources and form beans.

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?

  • validate(): This function is used to perform server-side validation of form inputs based on the validation rules defined in the ActionForm class.
  • reset(): This function determines whether to reset or delete form fields to their default values.

22. What are the condition for actionForm to work correctly?

ActionForm should follow the following conditions to work correctly.

  • ActionForm must have a no argument constructor.
  • For all properties, it should have public getter and setter methods.
  • It needs to extend the org.apache.struts.action.ActionForm class or it can implement the org.apache.struts.action.ActionForm interface.
  • It must be declared in the struts-config.xml file with a unique name and linked to the corresponding Action mapping.

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?

  • In Struts, when the logic for exception handling has defined within the action tag or in struts-config.xml file, it is known as declarative exception handling.
  • For this, we can specify how to handle specific exceptions thrown by actions like redirecting to different actions or displaying custom error pages etc. in struts configuration file.

Top 25 Struts Interview Questions and Answers for 2024

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

  • Struts Interview Questions for Freshers
  • Struts Interview Questions for Intermediate
  • Struts Interview Questions for Experienced

Similar Reads

Basic Struts Interview Questions for Freshers

Looking 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....

Struts Interview Questions for Intermediate

Intermediate 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....

Struts Interview Questions for Experienced

In 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....

Conclusion

In 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....

Contact Us