YouTube Icon

Interview Questions.

Struts Interview Questions and Answers - Jul 14, 2022

fluid

Struts Interview Questions and Answers

Q1. What is Struts? Why you have got used struts in your application or task.?

Ans: Struts are nothing however open supply framework usually used for making net utility whenever we use the term framework approach it accommodates JSP, servlet, custom tags message resources multi function package which makes developer task very clean. Its is primarily based on MVC pattern which is model view Controller sample.

If we go together with servlet all HTML code that's associated with layout part frequently will come inner java code which makes code unmaintainable and complicated in addition if use JSP, all java code related to commercial enterprise come inside layout component which again make code complicated, that’s why MVC pattern come into lifestyles and which separate the enterprise, layout and controller and struts had been made based totally on this sample and easy to develop internet software.

Q2. What are the additives of Struts.

Ans:

Action Servlet

Action Classes

Action Form

PlugIn Classes.

1 Validator Framework

2 Tiles

Message Resources

Action Mapping Implemention

Struts Configuration XML Files

Exception Handler

Q3. What are the primary instructions that are utilized in struts application?

Ans: Main classes in Struts Framework are:

Action servlet: it’s a backbone of net software it’s a controller magnificence liable for coping with the complete request.

Action magnificence: the use of Action training all of the commercial enterprise logic is developed us call model of the software additionally.

Action Form: it’s a java bean which represents our forms and related to movement mapping. And it also maintains the consultation nation its item is automatically populated on the server facet with statistics entered from a form at the customer aspect.

Action Mapping: the use of this class we do the mapping among object and Action.

ActionForward: this elegance in Struts is used to ahead the end result from controller to vacation spot.

Q4. What is Action.

Ans: Action is part of the controller. The use  of this elegance is to translate the

HTTP Servlet Request to the commercial enterprise logic.

A Struts movement is an instance of a subclass of an Action magnificence, which implements a portion of a Web software and whose carry out or execute technique returns a ahead.

Q5. What is Action Form.

Ans: ActionForm will maintains the session nation for net application and the its  item is automatically populated at the server side with statistics entered from a shape on the customer facet

Q6. What is Front Controller.

Ans: The Front Controller Pattern is a software program layout sample indexed in numerous pattern catalogs. The sample relates to the design of web programs. It “gives a centralized entry point for coping with requests.

Q7. What is the Difference between DispatchAction and LookupDispatchAction in Struts Framework?

Ans: This Struts interview query is quite straight forward and I have placed the differences in tabular layout to make it smooth to read.

Dispatch Action    LookupDispatchAction

It’s a determine class of  LookupDispatchAction    Subclass of Dispatch Action

DispatchAction gives a mechanism for grouping a hard and fast of associated features right into a unmarried movement, hence casting off the want to create separate moves for each feature.    An abstract Action that dispatches to the subclass mapped executes method. This is beneficial in instances in which an HTML form has a couple of put up buttons with the equal name. The button name is specified with the aid of the parameter assets of the corresponding ActionMapping.

If not using Internalization functionality then dispatch action is extra useful.    Lookup Dispatch Action is beneficial when we're using Internalization functionality

DispatchAction selects the technique to execute relying at the request parameter value that is configured inside the XML record.    LookupDispatchAction looks into the useful resource bundle document and finds out the corresponding key call. We can map this key call to a method name with the aid of overriding the getKeyMethodMap() technique.

DispatchAction isn't useful for I18N    LookupDispatchAction is used for I18N
 

Q8. What are Struts plugins.

Ans: Struts Plugins are modular extensions to the Struts COntroller. They are described by the org.Apache.Struts.Action.Plugin interface.Struts Plugins are beneficial are useful when you are allocating assets or preparing connections to the databases or maybe JNDI resources. This interface defines  lifecycle mathods: init() and desstroy().

Q9. How to name EJB from struts.

Ans: Subclass your Action elegance and Override execute() approach.

Then in body of execute() approach do this:

Get Initial Context

Get home item using JNDI appearance up.

Create the bean and phone teh business techniques.

We can name EJB from struts by means of the usage of the carrier locator layout sample or by Using preliminary context with create domestic object and getting go back far off referenc object.

Q10. What the Validate () and reset () method does?

Ans: validate(): validate technique is Used to validate properties when they had been populated, and this , approach is  Called earlier than FormBean is exceeded  to Action. Returns a set of ActionError as ActionErrors. Following is the method signature for the validate() technique.

Public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 

ActionErrors errors = new ActionErrors();

if ( StringUtils.IsNullOrEmpty(username) && StringUtils.IsNullOrEmpty(password))

mistakes.Add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.Usernamepassword.Required"));

go back errors;

 

reset(): reset() technique is referred to as by means of Struts Framework with every request that uses the described ActionForm. The motive of this approach is to reset all of the ActionForm's records contributors previous to the brand new request values being set.

Example :

public void reset(ActionMapping mapping, HttpServletRequest request) 

this.Password = null;

this.Username = null;

Set null for every request.

Q11. What is transfer movement

Ans: The SwitchAction cl provides a means to interchange from a useful resource in one module to another aid in a different module. SwitchAction is useful only when you have more than one modules for your Struts application. The SwitchAction cl can be used as is, without extending.

Q12. Difference between Actionform and dform.

Ans:

An ActionForm represents an HTML shape that the user interacts with over one or more pages. You will provide properties to keep the state of the shape with getters and setters to get admission to them. Whereas, using DynaActionForm there's no want of providing homes to keep the nation. Instead these residences and their kind are declared within the struts-config.Xml

The DynaActionForm bloats up the Struts config record with the xml based totally definition. This receives demanding as the Struts Config record develop larger.

The DynaActionForm is not strongly typed because the ActionForm. This manner there may be no bring together time checking for the form fields. Detecting them at runtime is painful and makes you undergo redeployment.

ActionForm may be cleanly organized in packages as in opposition to the flat corporation in the Struts Config document.

ActionForm were designed to behave as a Firewall among HTTP and the Action instructions, i.E. Isolate and encapsulate the HTTP request parameters from direct use in Actions. With DynaActionForm, the property get admission to is no exceptional than using request.GetParameter( .. ).

DynaActionForm construction at runtime requires numerous Java Reflection (Introspection) equipment that may be averted.

Q13. What is Mapping Dispatch.

Ans: An summary Action that dispatches to a public technique that is named by way of the request parameter whose name is specific by way of the parameter belongings of the corresponding ActionMapping. This Action is beneficial for builders who opt to integrate many similar actions right into a single Action class, on the way to simplify their application layout.

Struts MappingDispatch Action (org.Apache.Struts.Actions.MappingDispatchAction) is one of the Built-in Actions furnished at the side of the struts framework.

The org.Apache.Struts.Movements.MappingDispatchAction elegance is a subclass oforg.Apache.Struts.Moves.DispatchAction class. This elegance permits a person to gather associated functions into a single action elegance. It  desires to create multiple impartial movements for every feature.

Q14. What configuration files are utilized in Struts?

Ans: ApplicationResources.Houses and struts-config.Xml these  documents are used to among the Controller and the Model.

Q15. How exceptions are dealt with in Struts utility?

Ans: This is little hard Struts interview query even though looks quite simple not each candidate is aware of approximately it. Below is my solution of this interview questions about Struts:

There are two approaches of coping with exception in Struts:

Programmatically coping with: the use of attempt  catch block in code where an exception can come and waft of code is also decided by means of programmer .Its a normal java language concept.

Declarative dealing with: There are  approaches once more either we outline <global-Exception> tag interior struts-config.XML file

<exception

key="stockdataBase.Error.InvalidCurrencyType"

path="/AvailbleCurrency.Jsp"

type="Stock.Account.IllegalCurrencyTypeException">

</exception>

The programmatic and Declarative way is every now and then additionally asked as observe-up questions are given candidate’s reaction on know-how on Struts.

Key: The key represents the important thing present in MessageResource.Homes record to explain the exception.

Type: The class of the exception passed off.

Path: The web page wherein the controls are to be accompanied is case exception happened

Q16.  Explain approximately token features in struts

Ans: The trouble of duplicate shape submission arises when a person clicks the Submit button more than once earlier than the reaction is despatched back. This may also result in inconsistent transactions and need to be avoided. In Struts this hassle may be dealt with by using the use of the saveToken() and isTokenValid() methods of Action magnificence. SaveToken() approach creates a token (a completely unique string) and saves that in the person’s cutting-edge session, whilst isTokenValid() exams if the token saved inside the user’s present day consultation is similar to that changed into handed because the request parameter.

Use the Action Token strategies to save you reproduction submits

There are techniques built into the Struts movement to generate one-use tokens. A token is positioned inside the session while a shape is populated and additionally into the HTML form as a hidden assets. When the form is again, the token is tested. If validation fails, then the form has already been submitted, and the user may be apprised.

SaveToken(request)

on the return trip,

isTokenValid(request)

resetToken(request)

Q17. What are the layout patterns utilized in struts.

Ans: Struts is primarily based on version 2 MVC (Model-View-Controller) architecture. Struts controller uses the command layout sample and the movement lessons use the adapter design pattern. The process() method of the RequestProcessor makes use of the template technique design pattern. Struts also enforce the following J2EE layout patterns.

           Service to Worker

          Dispatcher View

          Composite View (Struts Tiles)

           Front Controller

          View Helper

          Synchronizer Token

Q18. Is Struts green?

Ans: The Struts isn't handiest thread-secure but thread-dependent(instantiates every Action as soon as and allows other requests to be threaded thru the original object.

ActionForm beans decrease subclass code and shorten subclass hierarchies

The Struts tag libraries provide preferred-cause functionality

The Struts additives are reusable by means of the utility

The Struts localization strategies lessen the want for redundant JSPs

The Struts is designed with an open architecture--subclass available

The Struts is lightweight (five middle packages, 5 tag libraries)

The Struts is open supply and properly documented (code to be examined effortlessly)

The Struts is model neutral

Q19. What are the center instructions of Struts? 

Ans: Action, ActionForm, ActionServlet, ActionMapping, ActionForward are basic classes of Structs.

Q20. What helpers inside the form of JSP pages are supplied in Struts framework? 

Ans:

--struts-html.Tld

--struts-bean.Tld

--struts-good judgment.Tld




CFG