Top Ten Struts Interview Enquiry In Addition To Response - J2ee

This fourth dimension its Struts interview questions, After writing Spring interview questions few weeks dorsum I was thinking what to selection for my interview serial in addition to so I idea close whatever spider web framework, in addition to on that struts is my favorite. Struts are opened upwardly source framework used for spider web application. These Struts interview questions are based on my sense every bit good every bit collected yesteryear friends in addition to colleague in addition to they are non solely skilful for interview exercise but besides shows a novel administration of learning for anyone who is non real familiar amongst struts. The best way to occupation these interview questions does revise earlier going for whatever Struts interview or whatever Java or J2EE interview. I convey besides provided answers to these struts interview questions but you lot tin besides enquiry to a greater extent than on Google but these answers of struts are sufficient on interview perspective.


Struts Interview Questions Answer

Question 1: What is Struts? Why you lot convey used struts inwards your application or project.

 few weeks dorsum I was thinking what to selection for my interview serial in addition to so I idea abo Top 10 Struts Interview Question And Answer - J2EEAns: This is the showtime interview questions anyone asks inwards Struts to acquire the interview rolling. Most normally asked during the less senior level. Struts are zippo but opened upwardly source framework generally used for making spider web application whenever nosotros occupation the term framework agency it comprises JSP, servlet, custom tags message resources all inwards ane packet which makes developer chore real easy. Its is based on MVC pattern which is model sentiment Controller pattern.


Now why nosotros occupation Struts? So principal argue is if nosotros become amongst servlet all HTML code which is related to pattern component generally volition come upwardly within coffee code which makes code unmaintainable in addition to complex similarly if occupation JSP, all coffee code related to delineate concern come upwardly within pattern component which ane time to a greater extent than brand code complex, that’s why MVC pattern come upwardly into existence in addition to which dissever the business, pattern in addition to controller in addition to struts were made based on this pattern in addition to slowly to prepare spider web application. 

The keyword to reply this Struts interview questions is MVC pattern pattern, Front Controller Pattern in addition to amend menses administration which generally interviewer are looking to hear. You tin read to a greater extent than pattern pattern interview enquiry on my postal service 10 Interview enquiry on Singleton Pattern inwards Java

Question 2: What are the principal classes which are used inwards struts application?
Ans 2: This is closed to other beginner’s degree Struts interview question which is used to banking concern check how familiar candidate is amongst Struts framework in addition to API. Main classes inwards Struts Framework are:

Action servlet: it’s a backbone of spider web application it’s a controller cast responsible for treatment the entire request.
Action class: using Action classes all the delineate concern logic is developed us telephone weep upwardly model of the application also.
Action Form: it’s a coffee edible bean which represents our forms in addition to associated amongst activity mapping. And it besides maintains the session state its object is automatically populated on the server side amongst information entered from a cast on the customer side.
Action Mapping: using this cast nosotros do the mapping betwixt object in addition to Action.
ActionForward: this cast inwards Struts is used to frontward the upshot from controller to destination.


Question 3: How exceptions are handled inwards Struts application?

Ans: This is niggling tough Struts interview question though looks quite basic non every candidate knows close it. Below is my reply of this interview questions on Struts:

There are 2 ways of treatment exception inwards Struts:

Programmatically handling: using attempt {} pick out receive of block inwards code where an exception tin come upwardly in addition to menses of code is besides decided yesteryear programmer .its a normal coffee linguistic communication concept.

Declarative handling: There are 2 ways ane time to a greater extent than either nosotros define <global-Exception> tag within struts-config.XML file

<exception

      key="stockdataBase.error.invalidCurrencyType"

      path="/AvailbleCurrency.jsp"

      type="Stock.account.illegalCurrencyTypeException">
</exception>

The programmatic in addition to Declarative way is sometimes besides asked every bit follow-up questions are given candidate’s response on noesis on Struts.

Key: The key represents the key acquaint inwards MessageResource.properties file to depict the exception.
Type: The cast of the exception occurred.
Path: The page where the controls are to live followed is illustration exception occurred.


See Struts inwards Action for to a greater extent than details:


 few weeks dorsum I was thinking what to selection for my interview serial in addition to so I idea abo Top 10 Struts Interview Question And Answer - J2EE





Question 4: How validation is performed inwards struts application?

Ans: Another classic Struts interview enquiry it’s higher on a degree than previous interview questions because it’s related to of import validation concept on a spider web application. In struts validation is performed using validator framework, Validator Framework inwards Struts consist of 2 XML configuration files.

1. validator-rules.xml file: which contains the default struts pluggable validator definitions. You tin add together novel validation rules yesteryear adding an entry inwards this file. This was the master beauty of struts which makes it highly configurable.
2. Validation.xml files which comprise details regarding the validation routines that are applied to the dissimilar Form Beans.

These 2 configuration files inwards Struts should live placed somewhere within the /WEB-INF folder of the application to continue it prophylactic from the customer in addition to acquire inwards available inwards Classpath.

<!--  Validator plugin -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
  <set-property
  property="pathnames"
   value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

Now the side yesteryear side measuring towards validation is created fault messages within the message resources belongings file which are used yesteryear validator framework.
Message resources Contain:
1. CurrencyConverterForm.fromCurrency = From Currency
2. CurrencyConverterForm.toCurrency=To currency
3. errors.required={0} is required.

Then validation rules are defined inwards validation.xml for the fields of cast on which nosotros wishing want validation

Form edible bean code that extend DynaValidatorForm
Eg; <form-beans>
<form-bean name="CurrencyConverterForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="fromCurrency" type="java.lang.double" />
<form-property name="toCurrecny" type="java.lang.double" />
</form-bean>
</form-beans>

Validation.xml file contains

<form-validation>
<formset>
<form name=" CurrencyConverterForm ">
<field property=" fromCurrency " depends="required">
<arg key=" CurrencyConverterForm. fromCurrency "/>
</field>
<field property=" toCurrecny " depends="required ">
<arg key=" CurrencyConverterForm.toCurrency "/>
</field>
</form>
</formset>
</form-validation>

To associate to a greater extent than than ane validation dominion to the belongings nosotros tin specify a comma-delimited listing of values. The showtime dominion inwards the listing volition live checked showtime in addition to so the side yesteryear side dominion in addition to so on. Answer of this Struts questions gets combat longer but it’s of import to impact these of import concepts to acquire inwards useful.

Top 10 Interview Questions asked inwards Struts


Question 5: What is the Difference betwixt DispatchAction in addition to LookupDispatchAction inwards Struts Framework?

This Struts interview enquiry is pretty straight off frontward in addition to I convey seat the differences inwards tabular format to acquire inwards slowly to read.


Dispatch Action
LookupDispatchAction

It’s a nurture cast of  LookupDispatchAction
Subclass of Dispatch Action
DispatchAction provides a machinery for grouping a laid of related functions into a unmarried action, thence eliminating the demand to create dissever actions for each function.
An abstract Action that dispatches to the subclass mapped executes method. This is useful inwards cases where an HTML cast has multiple submit buttons amongst the same name. The push clit cite is specified yesteryear the parameter belongings of the corresponding ActionMapping.
If non using Internalization functionality so dispatch activity is to a greater extent than useful.

Lookup Dispatch Action is useful when nosotros are using Internalization functionality

DispatchAction selects the method to execute depending on the asking parameter value which is configured inwards the XML file.
LookupDispatchAction looks into the resources packet file in addition to finds out the corresponding key name. We tin map this key cite to a method cite yesteryear overriding the getKeyMethodMap() method.
DispatchAction is non useful for I18N

LookupDispatchAction is used for I18N




Question 6: How you lot tin yell upwardly the value which is laid inwards the JSP Page inwards the illustration of DynaActionForm?

Ans: DynaActionForm is a pop theme inwards Struts interview questions. DynaActionForm is a subclass of ActionForm that allows the creation of cast beans amongst dynamic sets of properties, without requiring the developer to create a Java cast for each type of cast bean. DynaActionForm eliminates the demand of FormBean cast in addition to at nowadays the cast edible bean definition tin live written into the struts-config.XML file. So, it makes the FormBean declarative in addition to this helps the programmer to cut back the evolution time.

For Example, nosotros convey a CurrencyConverterForm in addition to nosotros don't wishing a coffee class.
CurrencyConverterForm has properties fromCurrency, toCurrency

in the struts-config.xml file, declare the cast edible bean

<form-bean name=" CurrencyConverterForm "
type="org.apache.struts.action.DynaActionForm">
<form-property name=" fromCurrency " type="java.lang.String"/>
<form-property name=" toCurrency " type="java.lang. String "/>
</form-bean>

Add action mapping inwards the struts-config.xml file:

<action path="/convertCurrency" type="com.techfaq.action.ConvertCurrencyAction"
name=" CurrencyConverterForm "
scope="request"
validate="true"
input="/pages/ currencyConverterform.jsp">

<forward name="success" path="/jsp/success.jsp"/>
<forward name="failure" path="/jsp/error.jsp" />

</action>

In the Action class.

public cast ConvertCurrencyAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{

DynaActionForm currencyConverterForm = (DynaActionForm)form;

// yesteryear this way nosotros tin yell upwardly the value which is laid inwards the JSP Page

String fromCurrency = (String) currencyConverterForm.get("fromCurrency ");
String toCurrency = (String) currencyConverterForm.get("toCurrency ");
return mapping.findForward("success");
}
}
}

In the JSP page

<html:text property=" fromCurrency " size="30" maxlength="30"/>
<html:text property=" toCurrency " size="30" maxlength="30"/>


Question 7: what the Validate () in addition to reset () method does?

Ans: This is ane of my personal favorite Struts interview questions. validate(): validate method is Used to validate properties afterwards they convey been populated, in addition to this , method is  Called earlier FormBean is passed  to Action. Returns a collection of ActionError every bit ActionErrors. Following is the method signature for the validate() method.

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
                        
ActionErrors errors = novel ActionErrors();
if ( StringUtils.isNullOrEmpty(username) && StringUtils.isNullOrEmpty(password)){
     errors.add(ActionErrors.GLOBAL_ERROR, novel ActionError("error.usernamepassword.required"));
}
return errors;
}

reset(): reset() method is called yesteryear Struts Framework amongst each asking that uses the defined ActionForm. The purpose of this method is to reset all of the ActionForm's information members prior to the novel asking values beingness set.

Example :
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.password = null;
this.username = null;
}

Set zero for every request.

Question 8: How you lot volition brand available whatever Message Resources Definitions file to the Struts Framework Environment?

Ans: Message Resources Definitions file are uncomplicated .properties files in addition to these files comprise the messages that tin live used inwards the struts project. Message Resources Definitions files tin live added to the struts-config.xml file through < message-resources / > tag. Example: < message-resources parameter= MessageResources / >

Message resources definition files tin available to the struts environs inwards 2 ways
1. using web.xml as
<servlet>
<servlet-name>action<servlet-name>
servlet-class>org.apache.struts.action.ActionServlet<servlet-class>
<init-param>
<param-name>application<param-name>
<param-value>resource.Application<param-value>
</servlet>

2.
<message-resource key="myResorce" parameter="resource.Application" null="false">

Question 9: What configuration files are used inwards Struts?
Ans: ApplicationResources.properties in addition to struts-config.xml these 2 files are used to betwixt the Controller in addition to the Model.


Question 10: Explain Struts piece of work Flow?
Ans: Sometime this Struts interview questions asked every bit showtime questions but I recall this at nowadays J . Here is the answer to this Struts interview questions
 few weeks dorsum I was thinking what to selection for my interview serial in addition to so I idea abo Top 10 Struts Interview Question And Answer - J2EE
1) Influenza A virus subtype H5N1 asking comes inwards from a Java Server Page into the ActionServlet.
2) The ActionServlet having already read the struts-config.xml file knows which cast edible bean relates to this JSP, in addition to delegates piece of work to the validate method of that cast bean.

3) The cast edible bean performs the validate method to determine if all required fields convey been entered, in addition to performs whatever other types of patch validations that demand to live performed.

4) If whatever required patch has non been entered, or whatever patch does non transcend validation, the cast edible bean generates ActionErrors, in addition to afterwards checking all fields returns dorsum to the ActionServlet.

5) The ActionServlet checks the ActionErrors that were returned from the cast beans validate method to determine if whatever errors convey occurred. If errors convey occurred, it returns to the originating JSP displaying the appropriate errors.

6) If no errors occurred inwards the validate method of the cast bean, the ActionServlet passes command to the appropriate Action class.

7) The Action cast performs whatever necessary delineate concern logic, in addition to so forwards to the side yesteryear side appropriate activity (probably closed to other JSP).

That’s all on Struts interview enquiry answers, for now, at that topographic point are lots many interview questions on Struts which I convey non covered which you lot guys tin contribute in addition to I volition include it here. If you lot are looking to detect the reply to whatever enquiry asked on Struts interview then delight seat it hither in addition to I volition attempt to detect an reply to those questions.

Further Learning
Java Web Fundamentals By Kevin Jones
Struts 2 Framework for Beginners
Spring Framework Master Class - Beginner to Expert


Komentar

Postingan populer dari blog ini

Virtualbox - /Sbin/Mount.Vboxsf: Mounting Failed Amongst The Error: Protocol Fault [Solution]

Top Ten Jdbc Interview Questions Answers For Coffee Programmer

Fix Protocol As Well As Cause Messaging Interview Questions