Ads 468x60px

Pages

Wednesday, 4 July 2012

struts interview questions


Ques: 42 What is the difference between tiles:importAttribute and tiles:useAttribute tag in the Tiles framework?
Ans: The tiles:importAttribute tag imports all of the attributes in Tile scope into page scope. It is similar to the tiles:useAttribute tag. It is lazy, dirty and cheap.

Ques: 43 What is Tile controllers? How will you create your own Tile Controllers?
Ans: If you are putting too much java code into your Tile layout, or you have to put the same Java code into every Action that forwards to a page that uses a particular Tile layout, then you should use the Tile Controller.
The Controller class is similar to an Action. You can map model objects into scope so that the Tile can display the items. To write a Tile Controller, follow these steps:
  * Create a class that implements org.apache.struts.tiles.Controller.
  * Implement the perform method.
  * In the perform method, do something with the model and map the results into scope so that Tile can use it.

Ques: 44 Explain some of the Struts sub elements?
Ans: The sub-elements available to the top-level Struts components are:
  * The <icon/> Sub-Element: The <icon> sub-element contains <small-icon> and <large-icon> sub-elements that can be used to graphically represents its parent element in a Struts development tool.
      <icon>
         <small-icon>
          path to some graphics file
         <small-icon/>
         <large-icon>
          path to some graphics file
         <large-icon/>
      <icon/>
  * The <display-name/> Sub-Element: The <display-name> sub-element contains a short text description of its parent element for use in a Struts development tool.
    <display-name>
     short text description of its parent element.
    <display-name/>
  * The <descrition/> Sub-Element: The <description> sub-elementcontains a full length text description of its parent element for use in a Struts development tool.
    <descrition>
     full lenfth text description of its parent element.
    <descrition/>
  * The <set-property/> Sub-Element: You can use the <set-property> sub element to set the value of additional JavaBean properties of objects describe by the <set-property> sub-element's parenet.
    <set-property property="name of bean property" value="value of bean property"/>

Ques: 45 How can you add a DataSource in your struts-config file?
Ans:The first component that we configure is a DataSource.

  <data-sources>       
     <data-source>        
         <set-property property="driverClass" value="com.mysql.jdbc.Driver"/>        
         <set-property property="url" value="jdbc:mysql://localhost:3306/mydb"/>
         <set-property property="user" value="root" />  
         <set-property property="password" value="password" />     
     </data-source>
  </data-sources>

Ques: 46 How will you add FormBean Definitions in your struts configuration file?
Ans: The <form-bean> sub-element is used to describe an instance of a FormBean that is later bound to an Action.
  <form-bean>
   <form-bean name="unique bean name" type="fully qualified class name">
  </form-bean>

Ques: 47 How you can add the Global exception in your configuration file?
Ans:The <global-exception> sub-element is used to define n-number of <exception> sub-elements that are throwable by any Action in a Struts application. This sub-element acts as a container for all public <exception> sub-element.
The <exception sub-element> is used to associate a global exception with an ExceptionHandler.
The following declaration in struts-config.xml:
<global-exceptions>
    <exception
      key="qams.exception"
      type="java.lang.Exception"
      handler="com.qas.exceptions.QAMSExceptionHandler"/>
</global-exceptions>

Ques: 48 What are the various attributes of an <exception> sub-element in struts config file?
Ans: The attribute of an <exception> sub-element:
  * bundle  : A ServletContext attribute that names the resource bundle associated with the ExceptionHandler handling the defined <exception> elements.
  * className : The fully qualified class name of the configuration bean associated with the defined handler.
  * hanler : The fully qulified class name of the ExceptionHandler that will process the contained <exception> sub-element.
  * key : Used to retrieve the message template associated with this exception.
  * path : The module-relative path that will act as the target of the ExceptionHandler associated with this exception.
  * scope : The scope of the ActionError object coupled with this exception.(optional)
  * type : The fully qualified class name of the exception defined by this <exception> sub-element.(required).

Ques: 49 What is Global forwards and define its attributes in struts config file?
Ans: The <global-forwards> sub-elementis used to define n-number of <forward> sub-elements that are available to any Action in the Struts Application. It acts as a container for public <forward> sub-elements.
You can use <forward> sub-elements to describe a mapping of a logical name to a context relative URI path. A forward is used to identify the target of an Action class when it returns its result.
The Attributes of a <forward> sub element:
  * name : Contains the unique identifier identifying this target.
  * path : Specifies the Context relative path of the targeted resource.(required)
  * redirect : If set to true, causes the ActionServlet to use the HttpServletResponse.sendRedirect() method, as opposed to RequestDispatcher.forward() method, when sending the Action results to the targeted resourse. The default value is false.(optional)

Ques: 50 What is for <action-mapping> sub elements in struts config file?
Ans: The <action-mapping> sub-element is used to define n-number of <action> sub-elements. It acts as a container for <action> sub-elements.
The <action> sub-element is used to describe an Action instance to the ActionServlet.
<action-mappings>
        <action
            path="/logon"
            type="org.apache.struts.webapp.example.LogonAction"
            name="logonForm"
            scope="request"
            input="/logon.jsp"
            unknown="false"
            validate="true" />
    </action-mappings>

0 comments:

Post a Comment