Google

Interview Questions Test your java skills Java API Reference Notifications Java Forums Java Examples Tell a Friend
Link to us Donate
Javagalaxy.com WWW
Subscribe Un Subscribe

Java Interview Questions on your mobileNew            

Java Interview Questions - JavaGalaxy.com

  Java Interview Questions                       Is your Interview Question not answered here? Send it to webmaster@javagalaxy.com, we will answer it.

    Search Interview Questions 

  Displaying     Interview Questions and answers.

  Please click here to give us Feedback / Suggestions on how we can improve Java interview questions and answers

 
 Question   What is the name of the XML file which handles requests and gives responses? And acts
as a controller?  (Struts)  Discuss in Detail (QID: 583)
 Answer  Click on Discuss in Detail link for more details   struts-config.xml file

 Question   How would struts handle "messages" required for the application?  (Struts)  Discuss in Detail (QID: 582)
 Answer    Messages are defined in a .properties file as name value pairs. To make these messages
available to the application, you need to place the .properties file in WEB-INF/classes
folder. And define the following tag in struts-config.xml file

<message-resources parameter="ApplicationResources" />

And in order to display a message in a jsp you would use

<bean:message key="title.mytitle"/>

 Question   Do you write an ActionForm class for every form that you need to process?  (Struts)  Discuss in Detail (QID: 581)
 Answer  Click on Discuss in Detail link for more details   No, I define DynaValidatorForm as this class takes care of defining get/set methods and
doing the validation for me. And I need to define this class in struts-config.xml file. An e.g.
would be

<form-beans>

       <form-bean name="categoryForm" type="org.apache.struts.validator.DynaValidatorForm">
              <form-property name="category" type="java.lang.String"/>              
       </form-bean>

</form-beans>

 Question   Explain about Action Class  (Struts)  Discuss in Detail (QID: 580)
 Answer    The Action Class is part of the Model and is a wrapper around the business logic. The
purpose of Action Class is to translate the HttpServletRequest to the business logic. To
use the Action, we need to Subclass and overwrite the execute() method. In the Action
Class all the database/business processing are done. It is advisable to perform all the
database related stuffs in the Action Class. The ActionServlet (command) passes the
parameterize class to Action Form using the execute() method. The return type of the
execute method is ActionForward which is used by the Struts Framework to forward the request
to the file as per the value of the returned ActionForward object.

 Question   Explain about ActionForm class  (Struts)  Discuss in Detail (QID: 579)
 Answer    ActionForm class defines get and set methods for information provided by the client in the
HTML form. It has reset (for reseting the defined variables to its initital state) and
validate method for validating the user input.

 Question   Brief on how struts validation is working  (Struts)  Discuss in Detail (QID: 578)
 Answer    Struts uses 2 XML files to validate the user form. validator-rules.xml and validation.xml
files. The validator-rules.xml defines a set of standard validations and these validations
are used in validation.xml file.

Generally the rules defined in validator-rules.xml file are typical java class files that does
the validation in the backend.

 Question   What happens when the user has not provided required information that is needed by the struts
validator framework? Explain how struts handles to display the validation messages?  (Struts)  Discuss in Detail (QID: 577)
 Answer    When the user has not provided any required information, the validation messages are
displayed to the user and this block of code does this job.

<logic:messagesPresent>
<bean:message key="errors.header.login"/>
<ul>
<html:messages id="error">
<li><bean:write name="error"/></li>
</html:messages>
</ul><hr />
</logic:messagesPresent>

 Question   How you will enable front-end validation based on the xml in validation.xml?  (Struts)  Discuss in Detail (QID: 576)
 Answer    The <html:javascript> tag to allow front-end validation based on the xml in validation.xml.
For example the code: <html:javascript formName="logonForm" dynamicJavascript="true"
staticJavascript="true" /> generates the client side java script for the form "logonForm" as
defined in the validation.xml file. The <html:javascript> when added in the jsp file generates
the client site validation script.

 Question   Can you write your own method in Action class other than execute() and call that user method
directly?  (Struts)  Discuss in Detail (QID: 575)
 Answer    Yes, We can create any number of methods in Action class and instruct the action tag in
struts-config.xml file to call that user method. This is possible by using DispatchAction class.

A sample code would look like this

public class StudentAction extends DispatchAction
{
       public ActionForward create(ActionMapping mapping, ActionForm form,
HttpServletRequest req,
                                          HttpServletResponse res) throws Exception
       {
              return something;
       }

       public ActionForward read(ActionMapping mapping, ActionForm form,
HttpServletRequest req,
                                          HttpServletResponse res) throws Exception
       {
              return something;
       }

       public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest req,
                                          HttpServletResponse res) throws Exception
       {
              return something;
       }

}


In the above Action class if the user wants to call any method, he would do something
like this in my struts-config.xml file

<action path="/somePage"
       type="StudentAction"
       name="studentForm"
       <b>parameter="methodToCall"</b>
       scope="request"
       validate="true"
       input="/student.jsp">
       
<forward name="success" path="/success.jsp"/>
</action>

In this configuration file the value of the parameter methodToCall determines the method in
the StudentAction class to be invoked. For example, the JSP from which you are calling this
action, can set the methodToCall parameter to any of the methods it wants to.

 Question   What is the advantage of DispatchAction class?  (Struts)  Discuss in Detail (QID: 574)
 Answer    Using DispatchAction class you can overcome writing one Action class for one business entity.
Instead you can write multiple business entities in one Action class and call the business
method that is required by the application.

 
First Previous Showing 11 - 20 of 20 Records    Jump to page number       Current page number: 2

Displaying records per page

   - Discussions are available

Copyright © 2002 - 2010 JavaGalaxy.com,
All Rights Reserved Advertise| Feedback| Contact us| Terms of Use| Privacy Policy|

Help us to keep serving you better.
If you find any part of this site useful please support the site by linking to us