Top X Struts Interview Query 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 as well as so I idea most whatever spider web framework, as well as 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 equally good equally collected yesteryear friends as well as colleague as well as they are non alone expert for interview practise but likewise shows a novel administration of learning for anyone who is non really familiar amongst struts. The best way to utilization these interview questions does revise earlier going for whatever Struts interview or whatever Java or J2EE interview. I convey likewise provided answers to these struts interview questions but you lot 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 you lot convey used struts inwards your application or project.

 few weeks dorsum I was thinking what to alternative for my interview serial as well as 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 unremarkably asked during the less senior level. Struts are nix but opened upwardly source framework generally used for making spider web application whenever nosotros utilization the term framework agency it comprises JSP, servlet, custom tags message resources all inwards 1 parcel which makes developer trouble really easy. Its is based on MVC pattern which is model thought Controller pattern.


Now why nosotros utilization Struts? So psyche argue is if nosotros become amongst servlet all HTML code which is related to pattern component division generally volition come upwardly within coffee code which makes code unmaintainable as well as complex similarly if utilization JSP, all coffee code related to describe of piece of employment organisation come upwardly within pattern component division which over again brand code complex, that’s why MVC pattern come upwardly into existence as well as which split the business, pattern as well as controller as well as struts were made based on this pattern as well as slow to prepare spider web application. 

The keyword to reply this Struts interview questions is MVC pattern pattern, Front Controller Pattern as well as meliorate menstruation administration which generally interviewer are looking to hear. You tin read to a greater extent than pattern pattern interview inquiry on my ship service 10 Interview inquiry on Singleton Pattern inwards Java

Question 2: What are the psyche classes which are used inwards struts application?
Ans 2: This is around other beginner’s score Struts interview question which is used to banking company check how familiar candidate is amongst Struts framework as well as API. Main classes inwards Struts Framework are:

Action servlet: it’s a backbone of spider web application it’s a controller shape responsible for treatment the entire request.
Action class: using Action classes all the describe of piece of employment organisation logic is developed us telephone telephone model of the application also.
Action Form: it’s a coffee edible bean which represents our forms as well as associated amongst activeness mapping. And it likewise maintains the session dry reason its object is automatically populated on the server side amongst information entered from a shape on the customer side.
Action Mapping: using this shape nosotros do the mapping betwixt object as well as Action.
ActionForward: this shape inwards Struts is used to frontwards the final result from controller to destination.


Question 3: How exceptions are handled inwards Struts application?

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

There are 2 ways of treatment exception inwards Struts:

Programmatically handling: using attempt {} grab block inwards code where an exception tin come upwardly as well as menstruation of code is likewise decided yesteryear programmer .its a normal coffee linguistic communication concept.

Declarative handling: There are 2 ways over again 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 as well as 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 introduce inwards MessageResource.properties file to depict the exception.
Type: The shape 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 alternative for my interview serial as well as 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 inquiry it’s higher on a score 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 copy 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 pop off on it security from the customer as well as 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 mensuration towards validation is created mistake 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 shape 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 1 validation dominion to the belongings nosotros tin specify a comma-delimited listing of values. The showtime dominion inwards the listing volition live checked showtime as well as so the side yesteryear side dominion as well as so on. Answer of this Struts questions gets chip longer but it’s of import to deportment on these of import concepts to acquire inwards useful.

Top 10 Interview Questions asked inwards Struts


Question 5: What is the Difference betwixt DispatchAction as well as LookupDispatchAction inwards Struts Framework?

This Struts interview inquiry is pretty lead frontwards as well as I convey set the differences inwards tabular format to acquire inwards slow to read.


Dispatch Action
LookupDispatchAction

It’s a rear shape of  LookupDispatchAction
Subclass of Dispatch Action
DispatchAction provides a machinery for grouping a laid of related functions into a unmarried action, therefore eliminating the demand to create split actions for each function.
An abstract Action that dispatches to the subclass mapped executes method. This is useful inwards cases where an HTML shape has multiple submit buttons amongst the same name. The push cite is specified yesteryear the parameter belongings of the corresponding ActionMapping.
If non using Internalization functionality so dispatch activeness 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 parcel file as well as 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 remember 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 shape beans amongst dynamic sets of properties, without requiring the developer to create a Java shape for each type of shape bean. DynaActionForm eliminates the demand of FormBean shape as well as straight off the shape edible bean definition tin live written into the struts-config.XML file. So, it makes the FormBean declarative as well as this helps the programmer to cut the evolution time.

For Example, nosotros convey a CurrencyConverterForm as well as nosotros don't wishing 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 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 shape 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 remember 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 () as well as reset () method does?

Ans: This is 1 of my personal favorite Struts interview questions. validate(): validate method is Used to validate properties afterwards they convey been populated, as well as 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 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 as well as 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 as well as struts-config.xml these 2 files are used to betwixt the Controller as well as the Model.


Question 10: Explain Struts piece of employment Flow?
Ans: Sometime this Struts interview questions asked equally showtime questions but I recall this straight off J . Here is the answer to this Struts interview questions
 few weeks dorsum I was thinking what to alternative for my interview serial as well as 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 shape edible bean relates to this JSP, as well as delegates piece of employment to the validate method of that shape bean.

3) The shape edible bean performs the validate method to determine if all required fields convey been entered, as well as performs whatever other types of acre validations that demand to live performed.

4) If whatever required acre has non been entered, or whatever acre does non move yesteryear validation, the shape edible bean generates ActionErrors, as well as 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 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 shape bean, the ActionServlet passes command to the appropriate Action class.

7) The Action shape performs whatever necessary describe of piece of employment organisation logic, as well as so forwards to the side yesteryear side appropriate activeness (probably around other JSP).

That’s all on Struts interview inquiry answers, for now, at that spot are lots many interview questions on Struts which I convey non covered which you lot guys tin contribute as well as I volition include it here. If you lot are looking to notice the reply to whatever inquiry asked on Struts interview then delight set it hither as well as I volition attempt to notice 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


Belum ada Komentar untuk "Top X Struts Interview Query In Addition To Answer - J2ee"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel