Jakarta struts questions

A reader sent it a set of Jakarta Struts questions used at his company.

  1. What is Jakarta Struts Framework? - Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
  2. What is ActionServlet? - The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.
  3. How you will make available any Message Resources Definitions file to the Struts Framework Environment? - Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through <message-resources /> tag.
    Example:
    <message-resources parameter=”MessageResources” />
         
  4. What is Action Class? - 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 (commad) passes the parameterized 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.
       
  5. Write code of any Action Class? - Here is the code of Action Class that returns the ActionForward object.
     import javax.servlet.http.HttpServletRequest;
     import javax.servlet.http.HttpServletResponse;
     import org.apache.struts.action.Action;
     import org.apache.struts.action.ActionForm;
     import org.apache.struts.action.ActionForward;
     import org.apache.struts.action.ActionMapping;
    
    public class TestAction extends Action
    {
       public ActionForward execute(
         ActionMapping mapping,
         ActionForm form,
         HttpServletRequest request,
         HttpServletResponse response) throws Exception
    	{
    	       return mapping.findForward("testAction");
    	}
     }
    
  6. What is ActionForm? - An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.
      
  7. What is Struts Validator Framework? - Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class. The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
       
  8. Give the Details of XML files used in Validator Framework? - The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.
  9. How you will display validation fail errors on jsp page? - The following tag displays all the errors:
    <html:errors/>
      
  10. How you will enable front-end validation based on the xml in validation.xml? - 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.
This entry was posted in Java. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

26 Comments on Jakarta struts questions

  1. Siva
    Posted 1/4/2006 at 8:04 am | Permalink

    Hi,

    I want to know why do we need abstarct class, methods and its advnatges. Please send me answer for my questions

  2. Scott
    Posted 3/3/2006 at 10:58 am | Permalink

    Can the STRUTS nested tags support many parent to child relationships in one bean? i.e. a bean of many chapters contains a collection of many sections which belong to a chapter

    The chapter bean with a collection of sections contains…
    Chapter One
    Section A
    Section B
    Chapter Two
    Section C
    Section D

    It appears I have loaded the beans and collection correctly, but I can not get them to display correct. I get all the chapters and only the last section added to the collection.

  3. niranjan
    Posted 6/25/2006 at 9:32 pm | Permalink

    hai ,
    this is ravi.anyone pls give me the diff.between validate() and reset() methods in FormBean in struts

  4. Posted 7/10/2006 at 9:46 am | Permalink

    This is prasad.

    In the form bean the reset() method will set the default values. and validate() method provides the any validations carryout by manually. in this method u r providing the code for validations.

  5. Deven
    Posted 7/21/2006 at 4:44 pm | Permalink

    Hi
    I have one question.
    how do we configure web.xml using with MVC design pettern struts.
    Deven

  6. prasad
    Posted 7/26/2006 at 5:38 am | Permalink

    hi,

    1 . i want one answer i.e why java does not support multiple Inheitence?
    2 . Why we need reset() setter() methos in struts?

  7. prasad
    Posted 7/26/2006 at 5:41 am | Permalink

    1 . Why java does’nt support Multiple Inheritence?
    2. what is ment by setter() and reset() in struts?what is the difference b/w them and validite()?

  8. ranjithreddy
    Posted 8/17/2006 at 3:29 am | Permalink

    hi deven,
    we can configue with web.xml is we can forward the config from the action class in that web.xml class=actionclass name=formclass and path and input are given then it forwarded to what ever jsp page u want that can be given in the input.

  9. kartheekfresh
    Posted 9/21/2006 at 3:12 am | Permalink

    which class can be use EJB ans Where can be use EJB in Struts Architecture?

  10. Posted 10/16/2006 at 4:41 am | Permalink

    hi, i amith,i want to know what is the real use of actionmessages in realtime application.

  11. Balaji
    Posted 11/3/2006 at 6:45 am | Permalink

    Hi i am using struts validator framework for validating my form. Here i am stuck up with a problem
    i need to do email validation. I have written a function of my own to check for invalid characters. In validator.xml i am calling first that function thn email validation. i am getting 2 alerts where i should get only one if i am entering invalid characters in email feild.

    Help me on this..

  12. Rajani
    Posted 11/17/2006 at 1:42 am | Permalink

    setter() automatically sets the values from html into form bean .Reset() is used to change the values .validate() is used to for validation purpose

  13. javas
    Posted 1/31/2007 at 10:57 am | Permalink

    question 4’s answer appears to be incorrect.Action is not part of model.

    this is from “complete reference on struts” book:

    “Action classes provide the glue between the View and Model layers and are responsible for processing specific requests. Action classes are intended to transfer data from the View layer to a specific business process in the Model layer, and then to return data from the business process to the View layer. Business logic should not be embedded in actions, because that violates the principles of MVC.”

  14. Siva
    Posted 2/24/2007 at 11:18 am | Permalink

    bean.reset() is called when a new request is obtained, then the old request values will be reset in the form fields, Validate() is used to check the validation of the input parameters, like number format, min length, max length , if it has any error the new Action Error object is created and added with ActionErrors Object, the framework automatically reroute reposnse to the error page as u given in the action mappings tags attribute of input=”Error.jsp” in struts-config.xml file.

  15. Narendra Kharche
    Posted 5/8/2007 at 8:01 am | Permalink

    In strut framework when we use reset() it means that the new requestwill come and the previous request is not in real manner.
    The Validate() is used to check the validation of the input parameters, like number format, min length, max length , if any error is there, the new Action Error object is created and added with ActionErrors Object, the framework automatically reroute reposnse to the error page. The code is input=”Error.jsp” in struts-config.xml file.

  16. venkat
    Posted 5/31/2007 at 8:37 am | Permalink

    Interface contains 10 methods,if Class implents an inteface all methods will be excutes.Now question is I want to restrict one of the in iteface. It is possible if yes how?

  17. venkat
    Posted 5/31/2007 at 8:41 am | Permalink

    I want delete my table in database,before going to delete the Database can u check weather any Primary key or fkey is there or not(use java code)

  18. venkat
    Posted 5/31/2007 at 8:42 am | Permalink

    in interface contains 10 methods,i want restrict one method if i implement the class.is it possible pls explain

  19. venkat
    Posted 5/31/2007 at 8:43 am | Permalink

    in ArrayList can i remove or insert the elements in reverse order(Collection)

  20. venkat
    Posted 5/31/2007 at 8:44 am | Permalink

    When we will use Abstraction And Interface?

  21. venkat
    Posted 5/31/2007 at 8:45 am | Permalink

    If user close the Browser wile Our log file displaying in command promt.It will closed our JSP file ?

  22. venkat
    Posted 5/31/2007 at 8:46 am | Permalink

    Can u create new date using Java if yes how

  23. venkat
    Posted 6/1/2007 at 8:37 am | Permalink

    Pls any one help me this question.
    In EJB,Why the cleint can not communicate Dirctly in to EJBContaine?

  24. Asanthine.S
    Posted 7/17/2007 at 12:23 am | Permalink

    In strut framework when we use reset() it means that the new requestwill come and the previous request is not in real manner.
    The Validate() is used to check the validation of the input parameters, like number format, min length, max length , if any error is there, the new Action Error object is created and added with ActionErrors Object, the framework automatically reroute reposnse to the error page. The code is input=”Error.jsp” in struts-config.xml file.

  25. abhishek khandelwal
    Posted 10/3/2007 at 2:25 am | Permalink

    The answer of question number 4 is incorrect, the action class is not the part of the Model, It’s strongly coupled with ActionServlet i.e the Controller component of the Struts framework.

    Infact the struts doesn’t have any inbuilt support for model component, the action class acts as helper to Controller component.

  26. Kiran Talawai
    Posted 12/24/2007 at 6:46 am | Permalink

    When we will use Abstraction And Interface?

    An Abstract class is used as a Single inheritence but Interface supports the muliple inheritance in java.
    An abstract class considers only the abstract methods which will become compulsary in the respective subclasses. But the interface methods must and should me implemented in the class that implements that interface.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*