• +91 9723535972
  • info@interviewmaterial.com

Struts Interview Questions and Answers

Struts Interview Questions and Answers

Question - 71 : - Library Dependency

Answer - 71 : - Struts 1.1 now depends on a handful of libraries from other Jakarta subprojects (e.g. Commons-Logging, Commons-Collections, etc.). Some of these libraries may cause classloading conflicts in some servlet containers. So far, people have reported in the mailing list the classloading problem of commons-digester/jaxp1.1, and commons-logging causing deployment difficulties in Struts 1.1 applications running on Weblogic 6.0. (The problems have been corrected in Weblogic 6.1 and 7.0.)

Question - 72 : - Resources under WEB-INF

Answer - 72 : - According to the Servlet specification, resources (e.g. JSP files) stored under WEB-INF are protected and cannot be accessed directly by the browsers. One design idiom for Struts 1.0 is to put all the JSP files under WEB-INF and front them by Actions so that clients cannot illegally access the JSPs. With the introduction of sub-application prefixes in Struts 1.1, mapping resources under WEB-INF gets complicated. Extra configuration steps utilizing the pagePattern and forwardPattern attributes of the element in struts-config.xml is required to inform Struts to construct the paths correctly. More specifically, you need to set these attributes to the pattern "/WEB-INF/$A$P".

Question - 73 : - What is the Jakarta Struts Framework?

Answer - 73 : - Jakarta Struts is an open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is a robust architecture and can be used for the development of applications of any size.

Question - 74 : - What is an ActionServlet?

Answer - 74 : - The class org.apache.struts.action.ActionServlet is called the ActionServlet. In the Jakarta Struts Framework this class plays the role of controller. All the requests to the server go through the “Controller”. The “Controller” is responsible for handling all the requests.

Question - 75 : - How can one make any “Message Resources” definitions file available to the “Struts Framework” environment?

Answer - 75 : - Answer: “Message Resources” definitions file are simple .properties files and these files contain the messages that can be used in the struts project. “Message Resources” definition files can be added to the struts-config.xml file through tag. Example:

Question - 76 : - What is an “Action Class”?

Answer - 76 : - The “Action Class” is part of the “Model” and is a wrapper around the business logic. The purpose of the “Action Class” is to translate the HttpServletRequest to the business logic. To use the “Action”, we need to subclass and overwrite the execute() method. All the database and business processing is done in the “Action” class. It is advisable to perform all the database related work in the “Action” class. The ActionServlet (command) passes the parameterized class to ActionForm using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file according to the value of the returned ActionForward object.

Question - 77 : - Direct Requests to JSPs

Answer - 77 : - To take the full advantage of sub-application support, Struts 1.1 stipulates the requirement that all requests must flow through the controller servlet, i.e. the ActionServlet. Effectively, this means all JSPs must be fronted by Actions. Instead of allowing direct requests to any of the JSPs, all requests must go through an Action and let the Action forward to the appropriate JSP. This is perhaps the biggest impact of migration to Struts 1.1 if you have not followed this idiom in your applications. This restriction is required because without going through the ActionServlet, Struts navigation taglibs (e.g. and ) used in the JSPs will not have the correct sub-app context to work with.

Question - 78 : - What is an “ActionForm”?

Answer - 78 : - An “ActionForm” is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the “ActionForm” object is automatically populated on the server side with data entered from a form on the client side.  What is Struts Validator Framework? The “Struts Framework” provides the functionality to validate the form data. It can be used to validate the data in the user’s browser as well as on the server side. Struts Framework checks the JavaScript code and it can be used to validate the form data on the client browser. Server side validation of form data can be accomplished by subclassing your “form” Bean with DynaValidatorForm class. The “Validator” framework was developed by David Winterfeldt as a third-party “add-on” to Struts. Now the Validator framework is part of the “Jakarta Commons” project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without any making any additional settings. Describe the details of XML files used in the “Validator Framework”? The Validator Framework uses two XML configuration files 1) validator-rules.xml and 2) validation.xml. The validator-rules.xml defines the standard validation routines. These are reusable and used in validation.xml to define the form specific validations. The validation.xml defines the validations applied to a form bean.

Question - 79 : - How would you display “validation fail” errors on a JSP page?

Answer - 79 : - Following tag displays all the errors:  

Question - 80 : - How can one enable front-end validation based on the xml in validation.xml?

Answer - 80 : - The  tag allows front-end validation based on the xml in validation.xml. For example the code: generates the client side JavaScript for the form "logonForm" as defined in the validation.xml file. The when added in the JSP file generates the client side validation script.  


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners