Java Struts Interview Questions & Answers

4 avg. rating (80% score) - 1 votes

Java Struts Interview Questions & Answers

Finding another job can be so cumbersome that it can turn into a job itself. If you are expertise in Java then prepare well for the job interviews to get your dream job. Here's our recommendation on the important things to need to prepare for the job interview to achieve your career goals in an easy way. Java Struts is the most popular framework for developing Java based web applications. Struts is being developed as an open source project started by Apache Software Foundation . Struts framework is based on Model View Controller (MVC) architecture. Developers use it for developing. Follow our Wisdomjobs page for Java Struts job interview questions and answers page to get through your job interview successfully in first attempt.

Java Struts Interview Questions

Java Struts Interview Questions
    1. Question 1. What Are The Components Of Struts Framework?

      Answer :

      Struts framework is composed of following components:
      1. Based on the Model-View-Controller (MVC) design paradigm, distinctly separating all three levels:
      Model: application state
      View: presentation of data (JSP, HTML)
      Controller: routing of the application flow
      2. A request handler provided by the application developer that is used to  mapped to a particular URI.
      3. A response handler which is used to transfer the control to another resource which will be responsible for completing the response.
      4. A tag library which helps developers to create the interactive form based applications with server pages.
      5. Java Servlets
      6. JSP (Java Server Pages)
      7. Custom Tags
      8. Message Resources

    2. Question 2. What Is The Advantage Of Having A Pojo Class As An Action?

      Answer :

      The POJO class is light weight and easy to test with frameworks like Junit. Moreover, there is no need to create separate ActionForms as in struts one to hold the values from the source web page. It is done by a single POJO class in struts 2.

    3. Question 3. Which File Is Used By Controller To Get Mapping Information For Request Routing?

      Answer :

      Controller uses a configuration file “struts-config.xml file to get all mapping information to decide which action to use for routing of user’s request.It work as the router in the network and process and map the request to the associated action or resource.

    4. Question 4. What’s The Role Of Action Class In Struts?

      Answer :

      In Struts, Action Class acts as a controller and performs following key tasks:
      1.After receiving user request, it processes the user’s request.
      2.Uses appropriate model and pulls data from model (if required).
      3.Selects proper view to show the response to the user.

    5. Question 5. What Is Struts Validator Framework?

      Answer :

      Struts Validator Framework enables us to validate the data of both client side and server side.
      There are two types of validation supported in the struts framework:-
        1. Clint side validation (Using java script support and enabling  java script in ur browser).
        2. Server site validation (using Validator method or ActionServlet class and).
      There is another way which is defining the rules of validation in validation-rule.xml file.
      When some data validation is not present in the Validator framework, then programmer can generate own validation logic, this User Defined Validation logic can be bind with Validation Framework.
      Validation Framework consist of two XML configuration Files:
      1. Validator-Rules.xml file
      2. Validation.xml file

    6. Question 6. What Are The Steps Of Struts Installation?

      Answer :

      In order to use Struts framework, we only need to add Struts.Jar file in our development environment. Once jar file is available in the CLASSPATH, we can use the framework and develop Strut based applications.

    7. Question 7. How Duplicate Form Submission Can Be Controlled In Struts?

      Answer :

      In Struts, action class provides two important methods which can be used to avoid duplicate form submissions.
      saveToken() method of action class generates a unique token and saves it in the user’s session.isTokenValid() method is used then used to check uniqueness of tokens.

    8. Question 8. In Struts, How Can We Access Java Beans And Their Properties?

      Answer :

      Bean Tag Library is a Struts library which can be used for accessing Java beans.

    9. Question 9. Which Configuration File Is Used For Storing Jsp Configuration Information In Struts?

      Answer :

      For JSP configuration details, Web.xml file is used.

    10. Question 10. What’s The Difference Between Validation.xml And Validator-rules.xml Files In Struts Validation Framework?

      Answer :

      In Validation.xml, we define validation rules for any specific Java bean while in validator-rules.xml file, standard and generic validation rules are defined.

    11. Question 11. What’s The Use Of Struts.xml Configuration File?

      Answer :

      Struts.xml file is one the key configuration files of Struts framework which is used to define mapping between URL and action. When a user’s request is received by the controller, controller uses mapping information from this file to select appropriate action class.

    12. Question 12. What’s The Significance Of Logic Tags In Struts?

      Answer :

      Use of logic tags in Struts helps in writing a clean and efficient code at presentation layer without use of scriptlets. 

    13. Question 13. What Is Actionmapping?

      Answer :

      Action mapping contains all the deployment information for a particular Action bean. This class is to determine where the results of the Action will be sent once its processing is complete.

    14. Question 14. What Are The Benefits Of Struts Framework?

      Answer :

      Struts is based on MVC and hence there is a good separation of different layers in Struts which makes Struts applications development and customization easy. Use of different configuration files makes Struts applications easily configurable. Also, Struts is open source and hence, cost effective.

    15. Question 15. Why Actionservlet Is Singleton In Struts?

      Answer :

      In Struts framework, actionServlet acts as a controller and all the requests made by users are controlled by this controller. ActionServlet is based onsingleton design patter as only one object needs to be created for this controller class. Multiple threads are created later for each user request.

    16. Question 16. How Properties Of A Form Are Validated In Struts?

      Answer :

      For validation of populated properties, validate() method of ActionForm class is used before handling the control of formbean to Action class.

    17. Question 17. What Are Disadvantages Of Struts?

      Answer :

      Although Struts have large number of advantages associated, it also requires bigger learning curve and also reduces transparency in the development process.
      Struts also lack proper documentation and for many of its components, users are unable to get proper online resources for help.

    18. Question 18. What’s The Use Of Resourcebundle.properties File In Struts Validation Framework?

      Answer :

      resourcebundle.properties file is used to define specific error messages in key value pairs for any possible errors that may occur in the code.
      This approach helps to keep the code clean as developer doesn’t need to embed all error messages inside code.

    19. Question 19. How Many Servlet Controllers Are Used In A Struts Application?

      Answer :

      Struts framework works on the concept of centralized control approach and the whole application is controlled by a single servlet controller. Hence, we require only one servlet controller in a servlet application.

    20. Question 20. Which Model Components Are Supported By Struts?

      Answer :

      Struts support all types of models including Java beans, EJB, CORBA. However, Struts doesn’t have any in-built support for any specific model and it’s the developer’s choice to opt for any model.

    21. Question 21. Is Struts Thread Safe?

      Answer :

      Yes Struts are thread safe. In Struts, a new servlet object is not required to handle each request; rather a new thread of action class object is used for each new request.

    22. Question 22. What Configuration Changes Are Required To Use Resource Files In Struts?

      Answer :

      Resource files (.properties files) can be used in Struts by adding following configuration entry in struts-config.xml file:
      <message-resources parameter=”com.login.struts.ApplicationResources”/>

       

    23. Question 23. What Are The Core Classes Of Struts Framework?

      Answer :

      Following are the core classes provided by Struts Framework:
      1.Action Class
      2.ActionForm Class
      3.ActionMapping Class
      4.ActionForward Class
      5.ActionServlet Class

       

    24. Question 24. When Should Be Opt For Struts Framework?

      Answer :

      Struts should be used when any or some of the following conditions are true:
      1.A highly robust enterprise level application development is required.
      2.A reusable, highly configurable application is required.
      3.A loosely coupled, MVC based application is required with clear segregation of different layers.

       

    25. Question 25. What Design Patterns Are Used In Struts?

      Answer :

      Struts is based on model 2 MVC (Model-View-Controller) architecture. Struts controller uses the command design pattern and the action classes use the adapter design pattern. The process() method of the RequestProcessor uses the template method design pattern. Struts also implement the following J2EE design patterns.
      1.Service to Worker
      2.Dispatcher View
      3.Composite View (Struts Tiles)
      4.Front Controller
      5.View Helper
      6.Synchronizer Token

       

    26. Question 26. What Are The Different Kinds Of Actions In Struts?

      Answer :

      The different kinds of actions in Struts are:
      1.ForwardAction
      2.IncludeAction
      3.DispatchAction
      4.LookupDispatchAction
      5.SwitchAction

    27. Question 27. How Exceptions Are Handled In Struts Application?

      Answer :

      Exceptions are handled in struts by using any one of the following two ways:
      Programmatically handling: In this exception are handled by using try and catch block in program. Using this programmer can define how to handle the situation when exception arises.
      Declarative handling: In this exception handling is done by using the XML file. Programmer defines the exception handling logic in the XML file. 
      There are two ways of defining the exception handling logic in the XML file:
      1.Global Action Specific Exception Handler Definition.
      2.Local Action Specific Exception Handler Definition.

    28. Question 28. What Is Dispatchaction?

      Answer :

      1.The DispatchAction enable the programmer to combine together related function or class.
      2.Using Dispatch Action programmer can combine the user related action into a single UserAction. like add user, delete user and update user.
      3.DispatchAction execute the action based on the parameter value it receives from the user.

    29. Question 29. What Is Lookupdispatchaction?

      Answer :

      1.The LookupDispatchAction class is a subclass of DispatchAction.
      2.The LookupDispatchAction is used to call the actual method.
      3.For using LookupDispatchAction, first we should generate a subclass with a set of methods.
      4.It control the forwarding of the request to the best resource in its subclass.
      5.It does a reverse lookup on the resource bundle to get the key and then gets the method whose name is associated with the key into the Resource Bundle.

    30. Question 30. What Is Struts.devmode?

      Answer :

      The struts.devMode is used to make sure that framework is running in development mode or production mode by setting true or false. struts.devMode is set to false in production phase to reduce impact of performance. By default it is "false". 
      It is used because of the following reasons:
      Resource Reloading: Resource bundle reload on every request
      Modification: struts.xml can be modified without restarting or redeploying the application
      Error Handling: The error occurs in the application will be reported, as oppose to production mode.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Tutorial