Important Java Struts interview questions

Below are some of the very important java struts interview questions and answers.

Q21. State the purpose of the Struts.xml configuration file?

Ans: The Struts.xml file is a fundamental configuration file in the Struts framework that can be applied to define the mapping in between the action and URL. On receiving the user’s requests, the controller will use the information of the mapping to choose the suitable action class.

Q22. In struts how are the tag libraries defined?

Ans: Inside the configuration file (web.xml) in the <taglib> tag, the tag libraries are defined as below:

?

12

3

4

5

6

7

<taglib> 

<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

 

<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

 

</taglib>

Important Java Struts interview questions

Important Java Struts interview questions

Q23. In struts what is the importance of logic tags?

Ans: When you apply the logic tags in the struts, they will help you to write the codes in a clean and efficient manner, without using the scriplets.

Q24. Name the two scope kinds for form beans?

Ans: 1. Request Scope – Formbean value is present only in the current request.

2. Session Scope – Formbean values is present for all the requests from the current session.

Q25. In struts how to group all the related actions into a single group?

Ans: Dispatcher action class has to be used for grouping all multiple related actions into a single group.

Q26. When to apply the Switch Action?

Ans:  The Switch action works well while there is a modular app that has multiple modules that work separately. When we use this switch Action class, we will be able to shift from one resource model to another one from a different module app.
Q27. State the merits of the Struts framework?

Ans:  It is a MVC based one and so there is a fine separation of the different layers in the Struts that will make the strut based app customization and development easier. Usage of various configuration files will make the strut apps configurable easily. Since this is an open based source, it is cost-efficient.

Important Java Struts interview questions

Important Java Struts interview questions

Q28. Write down the steps to migrate from Struts1 to Struts2?

Ans:

  1. Shift Struts1 action Form to the Struts2 POJO.
  2. Secondly switch Struts1 configuration file (struts-config.xml) to the Struts2 configuration file (struts.xml)

Q29. In struts how are the properties of the form validated?

Ans: For validation of the populated properties, validate () method of the Action Form class is applied to validate the populated property prior to handling the control of form bean to the Action class.

Q30. State the function of reset method in the Action Form class?

Ans: This is utilized to clear off the value of a form prior to initialization for a fresh request.

Q31. What are the demerits of Struts?

Ans: Even though there are a lot of advantages that are associated with struts, it needs huge learning curve and it as well reduces the transparency during the development stage. The other issue is that it lacks appropriate documentation and the users are unable to find help from any online resources for many of the struts components.

Q32. State the purpose of resourcebundle.properties?

Ans: The resourcebundle.properties files are utilized for defining any particular error message in the key value pair, for any sort of potential errors which may come about in the code. The method as well aids to maintain clean code since the developer need not embed all the error messages inside the code itself.

Q33. Is it possible to have an html form property without the associated getter and setter form bean technique?

Ans: The getter and the setter technique from the form bean have to be defined for each and every html properties, or else there are chances of getting error in the application results.

Q34. In the strut apps how many of the servlets controller is used?

Ans: This frame work runs on the theory of a centralized control method and so the entire application is governed by one single servlets controller. And so we will need only one controller for the servlets application.

Q35. Is it possible to have several struts-config.xml files for a single strut application?

Ans: Yes, it is possible to have multiple Struts-config.xml files for one single application, but we will require the beneath configuration to do that:

?

12

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

<servlet> 

<servlet-name>action</servlet-name>

 

<servlet-class>

 

org.apache.struts.action.ActionServlet

 

</servlet-class>

 

<init-param>

 

<param-name>config</param-name>

 

<param-value>

 

/WEB-INF/struts-config.xml

 

/WEB-INF/struts-config_user.xml

 

/WEB-INF/struts-config_admin.xml

 

</param-value>

 

</init-param>

 

………….

 

………….

 

</servlet>

Q36. What is the model component that is supported by the Strut?

Ans: Java beans, CORBA, EJB and all other type of models are supported by struts. No specific model has an inbuilt support however, and the developer has to opt for it according to their choice.

Q37.  When is it useful to run include action?

Ans: This is useful while integration is needed in-between the servlets based app and Struts.

Q38. Is it safe to use Struts thread?

Ans: It is safe to use thread in Struts. For handling each of the requests, there is no necessity of a new servlets object in Struts. In fact, a fresh thread action is applied for each of the new requests.

Q39. While you use the resource file, what are the changes to be made in its configurations?

Ans:  Resource files (.properties files) has to be applied by appending the below configuration entry in the struts-config.xml file:

<message-resources parameter=”com.login.struts.ApplicationResources”/>

Q40. In struts how to use nested beans?

Ans: There is a Nested tag library in struts for this function. For nesting the beans in the struts, the user can use this library.

Q41. In Struts Framework what are the core groups?

Ans: Action class, Action forward class, Action mapping class, Action servlets class, Action form class.

Q42. Write the program to handle exceptions in struts?

Ans: It is possible to handle exceptions through this program:

?

12

3

4

5

6

7

8

9

10

11

try { 

// Struts code

 

}

 

Catch (Exception e) {

 

// exception handling code

 

}

Q43. Is Struts Framework a division of the J2EE?

Ans:  The framework of Strut is grounded from J2EE technology like the Java beans, JSP and Servlets but it isn’t a division of the J2EE standard.

Q44.  Write the program to configure action mapping?

Ans: The action mapping is configured with the configuration file struts-config.xml in the tag <action-mapping> like this:

?

12

3

4

5

6

7

8

9

10

11

<pre><action-mappings><action path=”/login”

type=”login.loginAction”

name=”loginForm”

input=”/login.jsp”

scope=”request”

validate=”true”>

<forward name=”success” path=”/index.jsp”/>

<forward name=”failure” path=”/login_error.jsp”/>

</action>

</action-mappings>

Q45. When can the Struts Framework be opted?

Ans: It can be opted effectively if the user needs any one or all of the below conditions:

  • An extremely strong enterprise level app development is needed.
  • A recyclable, extremely configurable app is needed.
  • For a MVC based app (loosely coupled) is needed for clearing the segregations at various layers.

Q46. In struts, why are action servlets unique?

Ans:  Action servlets is the controller and hence all the requests placed by the user are controlled with the help of this controller only. This is a singleton pattern designed since only one object has to be created in this class of controller. Multiple threads can be created for each of the user requests later on.

Q47. Write the steps to set up a validator framework for a strut based applciation?

Ans: The below mentioned steps has to be applied: – Wrong Spelling

  1. In WEB-INF directory place valdator-rules.xml and validation.xml files.
  2. Activate the validation plugin in the struts-config.xml file by adding:

?

12

3

4

<plug-in className=”org.apache.struts.validator.ValidatorPlugIn”><set-property property=”pathnames” value=”/WEB-INF/validator-rules.xml,

/WEB-INF/validation.xml”/>

</plug-in>

Q48. For view layer in Struts what are the technologies that could be used?

Ans: HTML, JSP, XML/XSLT, Velocity template, WML files and servlets can be used.

Q49. What conditions are needed for the correct functioning of Action form?

Ans: The below mentioned conditions needs to be accomplished for an action form to figure out correctly:

  • There should be a no argument constructor.
  • For all the properties, there should be a public getter and setter method.

Q50.  For check boxes and text boxes, what is the library provision in struts?

Ans: HTML Tags library is the facility provided in struts for this purpose.

Leave a Reply

Your email address will not be published.