Top X Struts Interview Interrogation In Addition To Answer - J2ee

This fourth dimension its Struts interview questions, After writing Spring interview questions few weeks dorsum I was thinking what to alternative for my interview serial in addition to and then I idea well-nigh whatever spider web framework, in addition to on that struts is my favorite. Struts are opened upward source framework used for spider web application. These Struts interview questions are based on my sense equally good equally collected past times friends in addition to colleague in addition to they are non alone adept for interview practise but likewise shows a novel management of learning for anyone who is non real familiar alongside struts. The best way to exercise these interview questions does revise earlier going for whatever Struts interview or whatever Java or J2EE interview. I bring likewise provided answers to these struts interview questions but yous tin likewise inquiry 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 yous bring used struts inward your application or project.

 few weeks dorsum I was thinking what to alternative for my interview serial in addition to and then I idea abo Top 10 Struts Interview Question And Answer - J2EEAns: This is the outset interview questions anyone asks inward Struts to acquire the interview rolling. Most ordinarily asked during the less senior level. Struts are zilch but opened upward source framework generally used for making spider web application whenever nosotros exercise the term framework way it comprises JSP, servlet, custom tags message resources all inward i parcel which makes developer chore real easy. Its is based on MVC pattern which is model persuasion Controller pattern.


Now why nosotros exercise Struts? So principal argue is if nosotros become alongside servlet all HTML code which is related to blueprint component generally volition come upward within coffee code which makes code unmaintainable in addition to complex similarly if exercise JSP, all coffee code related to draw of piece of occupation concern come upward within blueprint component which in i lawsuit to a greater extent than brand code complex, that’s why MVC pattern come upward into existence in addition to which split the business, blueprint in addition to controller in addition to struts were made based on this pattern in addition to slow to prepare spider web application. 

The keyword to reply this Struts interview questions is MVC blueprint pattern, Front Controller Pattern in addition to meliorate menstruum management which generally interviewer are looking to hear. You tin read to a greater extent than blueprint pattern interview inquiry on my post service 10 Interview inquiry on Singleton Pattern inward Java

Question 2: What are the principal classes which are used inward struts application?
Ans 2: This is unopen to other beginner’s bird Struts interview question which is used to cheque how familiar candidate is alongside Struts framework in addition to API. Main classes inward Struts Framework are:

Action servlet: it’s a backbone of spider web application it’s a controller degree responsible for treatment the entire request.
Action class: using Action classes all the draw of piece of occupation concern logic is developed us telephone telephone model of the application also.
Action Form: it’s a coffee edible bean which represents our forms in addition to associated alongside activity mapping. And it likewise maintains the session soil its object is automatically populated on the server side alongside information entered from a shape on the customer side.
Action Mapping: using this degree nosotros do the mapping betwixt object in addition to Action.
ActionForward: this degree inward Struts is used to forrad the number from controller to destination.


Question 3: How exceptions are handled inward Struts application?

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

There are 2 ways of treatment exception inward Struts:

Programmatically handling: using endeavour {} grab block inward code where an exception tin come upward in addition to menstruum of code is likewise decided past times programmer .its a normal coffee linguistic communication concept.

Declarative handling: There are 2 ways in i lawsuit 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 likewise asked equally follow-up questions are given candidate’s response on noesis on Struts.

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


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


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





Question 4: How validation is performed inward struts application?

Ans: Another classic Struts interview inquiry it’s higher on a bird 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 inward 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 past times adding an entry inward this file. This was the master copy beauty of struts which makes it highly configurable.
2. Validation.xml files which incorporate details regarding the validation routines that are applied to the dissimilar Form Beans.

These 2 configuration files inward Struts should live placed somewhere within the /WEB-INF folder of the application to conk along it security from the customer in addition to become far available inward 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 past times side measurement towards validation is created fault messages within the message resources holding file which are used past times 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 inward validation.xml for the fields of shape on which nosotros wish 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 i validation dominion to the holding nosotros tin specify a comma-delimited listing of values. The outset dominion inward the listing volition live checked outset in addition to and then the side past times side dominion in addition to so on. Answer of this Struts questions gets flake longer but it’s of import to deport on these of import concepts to become far useful.

Top 10 Interview Questions asked inward Struts


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

This Struts interview inquiry is pretty conduct forrad in addition to I bring seat the differences inward tabular format to become far slow to read.


Dispatch Action
LookupDispatchAction

It’s a raise degree 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 split actions for each function.
An abstract Action that dispatches to the subclass mapped executes method. This is useful inward cases where an HTML shape has multiple submit buttons alongside the same name. The push refer is specified past times the parameter holding of the corresponding ActionMapping.
If non using Internalization functionality in addition to then 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 inward the XML file.
LookupDispatchAction looks into the resources parcel file in addition to finds out the corresponding key name. We tin map this key refer to a method refer past times overriding the getKeyMethodMap() method.
DispatchAction is non useful for I18N

LookupDispatchAction is used for I18N




Question 6: How yous tin cry back the value which is laid inward the JSP Page inward the representative of DynaActionForm?

Ans: DynaActionForm is a pop topic inward Struts interview questions. DynaActionForm is a subclass of ActionForm that allows the creation of shape beans alongside dynamic sets of properties, without requiring the developer to create a Java degree for each type of shape bean. DynaActionForm eliminates the demand of FormBean degree in addition to instantly the shape 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 down the evolution time.

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

in the struts-config.xml file, declare the shape 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 inward 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 degree ConvertCurrencyAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{

DynaActionForm currencyConverterForm = (DynaActionForm)form;

// past times this way nosotros tin cry back the value which is laid inward 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 i of my personal favorite Struts interview questions. validate(): validate method is Used to validate properties afterwards they bring been populated, in addition to this , method is  Called earlier FormBean is passed  to Action. Returns a collection of ActionError equally 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 past times Struts Framework alongside 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 existence set.

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

Set zero for every request.

Question 8: How yous 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 incorporate the messages that tin live used inward 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 inward 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 inward 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 occupation Flow?
Ans: Sometime this Struts interview questions asked equally outset questions but I recall this instantly J . Here is the answer to this Struts interview questions
 few weeks dorsum I was thinking what to alternative for my interview serial in addition to and then I idea abo Top 10 Struts Interview Question And Answer - J2EE
1) H5N1 asking comes inward from a Java Server Page into the ActionServlet.
2) The ActionServlet having already read the struts-config.xml file knows which shape edible bean relates to this JSP, in addition to delegates piece of occupation to the validate method of that shape bean.

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

4) If whatever required land has non been entered, or whatever land does non top validation, the shape 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 shape beans validate method to determine if whatever errors bring occurred. If errors bring occurred, it returns to the originating JSP displaying the appropriate errors.

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

7) The Action degree performs whatever necessary draw of piece of occupation concern logic, in addition to and then forwards to the side past times side appropriate activity (probably unopen to other JSP).

That’s all on Struts interview inquiry answers, for now, at that spot are lots many interview questions on Struts which I bring non covered which yous guys tin contribute in addition to I volition include it here. If yous are looking to detect the reply to whatever inquiry asked on Struts interview then delight seat it hither in addition to I volition endeavour 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



Sumber https://javarevisited.blogspot.com/

0 Response to "Top X Struts Interview Interrogation In Addition To Answer - J2ee"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel