Ads 468x60px

Pages

Wednesday, 4 July 2012

struts interview questions


Ques: 76 Describe the <tiles:useAttribute/> and <tiles:importAttribute/> tags in Tiles tag library in Struts framewrok?
Ans: The <tiles:useAttribute/> tag is used to retrieve a Tiles object from the Tiles context and expose that object as a scriptlet variable. The <tiles:useAttribute/> tag has no body and supports five attribute:
name, id, className, scope, ignore.
The <tile:importAttribute/> tag is ues to import a Tiles object from the Tiles context into a JSP scriptlet variable, which is stored in the named scope. If the name and scope attributes are not included are not included in the tag instance, then all Tile objects stored in the Tiles context are imported and placed in page scope. The < tiles:importAttribute/> tag has no body and supports three attributes:
name, scope, ignore.

Ques: 77 Which tag can be used to initialize the Tiles definition factory in Struts framework?
Ans: The <tiles:initComponentDefintions/> tag is used to initialize the Tiles definition factory. This tag is evaluated only once or not at all if the factory has already been initialized by other means. The <tiles:initComponentDefinition/> has no body and supports two attributes:
  * file : The file containing your Tile definitions.(Required)
  * classname : The fully qualified classname of the definition factory being initialized. This class, if specified, must implement the org.apache.struts.tiles.DefinitionFactory.(Optional)

Ques: 78 What are the steps involved in installing the Logic tag library in your Struts application?
Ans: To use the Logic tag library in web application, You must complete the following steps:
  * Copy the TLD file packaged with this tag library struts-logic.tld) to the webapps/MyAppName/WEB-INF directory.
  * Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
  * Add the following <taglib> sub-element to the web.xml file of the Web application:
  <taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>
You must add the following taglib directive to each JSP that will leverage the HTML tag library:
  <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

Ques: 79 What is the use of <logic:empty/> and <logic:notEmpty/> tag defined by Logic tag library in Struts framework?
Ans: The <logic:empty/> tag evaluates its body if either the scripting variable identified by the name attribute or a property of the named scripting variable is equal to null or an empty string. The <logic:empty/> tag has a body type of JSP and supports three attributes:
  * name : Identifies the scripting variable being tested.
  * property : Identifies the data member of the scripting variable ot be tested.(optional)
  * scope : Defines the scope of the bean specified by the name attribute.
The <logic:notEmpty/> tag evaluates its body if either the scripting variable or property of the named scripting variable is not equal to null or an empty string. The <logic:empty/> tag has a body type of JSP and supports three attributes:
  * name : Specifies a scripting variable to be used as the variable being tested.(Required)
  * property : Specifies the data member of the scripting variable to be tested.(optional)
  * scope : Defines the scope of the bean specified by the name attribute.

Ques: 80 What is the use of <logic:equal/> and <logic:notEqual/> tag defined by Logic tag library in Struts framework?
Ans: The <logic:equal/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, property, parameter equals the constant value specified by the value attribute. The <logic:equal/> tag has a body of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.
Example:
<logic:equal name="user"
  property="age"
  value="<%= requiredAge %>">
  You are exactly at the right age.
</logic:equal>

The <logic:notEqual/> tag evaluates its body if the variable specified by any one of the attributes cookie, header, name, property, parameter is not equal to the constant value specified by the value attribute. The <logic:equal/> tag has a body of JSP and supports seven attributes:
value, cookie, header, name, property, parameter, scope.
Example:
<logic:notEqual name="user"
  property="age"
  value="<%= requiredAge %>">
  You are not at the right age.
</logic:equal>

struts interview questions


Ques: 66 What is the use of <html:javascript/> tag in the HTML tag library?
Ans: The <html:javascript/> tag is used to insert JavaScript validation methods based on the Commons Validator Plugin. The JavaScript methods used for validation are retrieved from the validator definition file using the formName as the index. The <html:javascript/> tag has no body and supports eight attributes:
cdata, dynamicJavaScript, formName, htmlComment, method, page, src, staticJavascript.

Ques: 67 What is the use of <html:message/> tag in HTML tag library used in Struts application?
Ans: The <html:message/> tag is used to display a collection of messages stored in an ActionErrors, ActionMessages, String, or String array object. 
The <html:message/> has a body type of JSP and supports eight attributes:
id, bundle, locale, name, property, header, footer, message.

Ques: 68 What is the difference between <html:option/> and <html:options/> tag in HTML tag library?
Ans: The <html:option/> tag is used to generate an HTML <input> element to type <option>, which represents a single option element nested inside a parent <select> element. The <html:option/> tag has a body type of JSP and supports eight attributes:
value, bundle, disabled, key, locale, style, styleId, styleClass.
The <html:options/> tag (as a child of the <html:select/> tag) is used to generate a list of HTML <option> elements. The <html:options/> tag has no body and support eight attributes:
collection, filter, labelName, lableProperty, name, property, style, styleClass.

Ques: 69 What is for <html:rewrite/> tag used defined by the HTML tag library?
Ans: The <html:rewrite/> tag is used to create a request URI based on the identical policies used with the <html:link/> tag but without the <a> element.
 The <html:rewrite/> tag has no body and supports 12 attributes:
anchor, forward, href, name, page, paramId, paramName, paramProperty, paramScope, property, scope, transaction.

Ques: 70 What are the steps involved in installing the Tiles tag library in your Struts application?
Ans: To use Tiles tag library in web application, You must complete the following steps:
  * Copy the TLD file packaged with this tag library struts-tiles.tld to the       webapps/MyAppName/WEB-INF directory.
  * Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
  * Add the following <taglib> sub-element to the web.xml file of the Web application:
  <taglib>
    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
  </taglib>
You must add the following taglib directive to each JSP that will leverage the Tiles tag library:
  <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

Ques: 71 What is the use of <tiles:insert/> tag in Tiles tag library in Struts framewrok?
Ans: The <tiles:insert/> tag is used to insert a Tiles template into a JSP. You must use the <tiles:put/> or <tiles:putList/> tags to substitute sub-components of the tile being inserted. 
The <tiles:insert/> tag has a body type of JSP and support 14 attributes:
template, components, page, definition, attribute, name, beanName, beanProperty, beanScope, flush, ignore, role, controllerUrl, controllerClass.

Ques: 72 What is the use of <tiles:definition/> tag in Tiles tag library in Struts framewrok?
Ans: The <tiles:definition/> tag is used to create a JavaBean representation of Tiles template definition that is stored in the named scope bound to the identifier named by id attribute. The <tiles:definition/> tag acts much like a runtime counterpart to the XML <definition/> found in the Tiles definition file. The <tiles:definition/> tag has a body type of JSP and supports six attribute:
id, scope, template, page, role, extends.

Ques: 73 What is for <tiles:put/> tag used in Tiles tag library in Struts framewrok?
Ans: The <tiles:put/> tag is used to define the equivalent of a parameter, representing a sub-component of a template, that will be used to the Tiles object. 
The <tiles:put/> tag has a body type of JSP and supports eight attribute:
name, value, direct, type, beanName, beanProperty, beanScope, role.

Ques: 74 What is the use of <tiles:putList/> tag in Tiles tag library in Struts framewrok?
Ans: The <tiles:putList/> tag is used to define a list of parameters that will passed as attribute to the Tiles object. The list is created from a collection of child <tiles:add/> tags. 
The <tiles:putList/> tag has a body type of JSP and supports a single attribute:
name : The name of the list being created.(Required)

Ques: 75 What is the use of <tiles:add/> and <tiles:get/> tags in Tiles tag library in Struts framewrok?
Ans: The <tiles:add/> tag is used to add parameters to a parameter as defined by a <tiles:putList/> tag. 
The <tiles:add/> tag has a body type of JSP and supports seven attributes:
beanName, beanProperty, beanScope, direct, role, type, value.
The <tiles:get/> tag is used to retrieve and insert parameters previously defined from the Tiles context. With the exception of ignore attribute being defaulted to true, this tag is functioanlly the same as the <tiles:insert/>. 
The <tiles:get/> tag has no body content and support four attributes:
name, ignore, flush, role.







struts interview questions


Ques: 58 How many types of tag libraries are available in the Struts framework?
Ans: Five types of tag libraries are available in the Struts framework:
  * HTML tag library.
  * Tiles tag library.
  * Logic tag library.
  * Template tag library.
  * Bean tag library.

Ques: 59 What is for <html:cancel/> tag in HTML tag library in the Struts framework?
Ans: The <html:cancel /> tag is used to render an HTML <input> element with an input type of cancel. 
The <html:cancel /> has a body type of JSP and support the 25 attributes:
accessKey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value.

Ques: 60 What is for <html:checkbox /> tag in HTML tag library in the Struts framework?
Ans: The <html:checkbox/> tag is used to render an HTML <input> element with an input type of checkbox. 
The <html:checkbox/> has a body type of JSP and supports 27 attribute:
indexed, name, accessKey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value.

Ques: 61 what is for <html:errors> tag in the HTML tag library? Define its attributes?
Ans:The <html:errors /> tag is used to display the ActionError objects stored in an ActionErrors collection. 
The <html:errors /> tag has a body type of JSP and support four attributes:
  * bundle : Specifies a MessageResources key of the resource bundle defined in the struts-config <message-resource> element.
  * locale : Specifies the session attribute containing the locale instance of the current. This locale is then used to select Locale-specific text messages.
  * name : Specifies the name of the request scope object that references the ActionErrors collection being displayed.
  * property : Specifies which error message should be displayed, based on each property contained in the ActionErrors collection.

Ques: 62 what is the use of <html:file/> tag? Name all the attributes of this tag?
Ans: The <html:file/> tag is used to create an HTML <file> element. This tag allows you to upload files that will be populated in named ActionForm's identified property. 
The <html:file/> tag has a body of JSP and supports 30 attributes:
indexed, name, accessKey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value, accept, maxlength, size.

Ques: 63 what is the use of <html:form/> tag? Name all the attributes of this tag?
Ans: The <html:form/> tag is used to create an HTML form. The form implicitly interacts with the named ActionForm bean to pre-populate the input fields values with the matching data members of the named bean. 
The <html:form/> tag has a body type of JSP and supports 13 attributes:
action, enctype, focus, focusIndex, method, onreset, onsubmit, scope, style, styleClass, styleId, target, type.

Ques: 64 What is for <html:html/> tag defined in the HTML tag library in struts framework?
Ans: The <html:html/> tag is used to render the top-level <html> element. 
The <html:html/> tag has a body type of JSP and supports two attributes:
  * locale : If set to true, then the Locale object named by the HTTP Accept-Language header is used to set the language preefrences.
  * xhtml : If set to true, causes an xml:lang attribute to be redered as an attribute of the generated <html> element.

Ques: 65 What is the difference between <html:image/> and <html:img/> tag in the HTML tag library in struts framework?
Ans: The <html:image/> tag is used to render an HTML <input> element with an input type of image. The image URL generated for this image is calculated using the value identified by the src or page attributes. You must specify one of the src or page attributes. 
The <html:image/> has a body type of JSP.
The <html:img/> tag is used to render an HTML <img> element. The image URL generated for this image is calculated using the value identified by the src or page attributes. You must specify one of the src or page attributes. The <html:img/> has no body.







struts interview questions


Ques: 51 Describe the attributes of <action> sub-element?
Ans: The attributes of <action> Sub-Element:
  * path : Represents the context-relative path of the submitted request.
  * type : Specifies the fully qualified class name of the Action class being described by this ActionMapping.
  * name : Identifies the name of the form bean, if any, that is coupled with Action being defined.
  * scope : Specifies the scope of the form bean that is bound to the desired Action. The default value is session.
  * input : Represents the context-relative path of the input form to which control should be returned if a validation error is encountered.
  * className : Specifies the fully qualified class name of the ActionMapping implementation class you want to use in when invoking this Action class.
  * forward : Represents the context-relative path of the servlet or JSP resource that will process this request.
  * include : Represents the context relative path of the servlet or JSP resource that will process this request. This attrubute is used if you do not want an Action to service the request to this path.

Ques: 52 What is for <controller> element used in the struts config file?
Ans: The <controller> element is used to define a ControllerConfig bean (org.apache.struts.config.ControllerConfig) that represents an applicaition's runtime module configuration.
The attributes of <controller> sub-element: bufferSize, className, contentType, inputForward, locale, maxFileSize, memFileSize, multipartClass, nocache, processorClass, tempDir.
Syntax:
<controller processorClass="MyRequestProcessor" nocache="true" />

Ques: 53 How will you add a message Resource in your struts config file?
Ans: The <message-resources> element is used to describe a MessageResources object for the containing application.
Syntax:
<message-resources parameter="configuration parameter" key="main" />
The attribute of a <message-resources> Element: className, factory, key, null, parameter.

Ques: 54 How will you configure Plugins in your struts configuration file?
Ans: The <plug-in> element is used to add Plugins to the Struts Controller. Struts Plugins are useful when allocating resources or preparing connections to databases or even JNDI resources. The <plug-in> element has a single attribute, className, which is used to define the fully qualified Plugin class.
Syntax:
<plug-in className="Fully qualified plugin class name" />

Ques: 55 What are the steps involved in installing the HTML tag library in your Struts application?
Ans: To use HTML tag library in web application, You must complete the following steps:
  * Copy the TLD file packaged with this tag library struts-html.tld) to the webapps/MyAppName/WEB-INF directory.
  * Make sure that the struts.jar file is in the webapps/MyAppName/WEB-INF/lib directory.
  * Add the following <taglib> sub-element to the web.xml file of the Web application:
  <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>

You must add the following taglib directive to each JSP that will leverage the HTML tag library:
  <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

Ques: 56 What is for <html:base/> tag in the HTML tag library defined in the Struts.
Ans: The <html:base/> tag is used to insert an HTML <base> element, including an href pointing to the absolute location of the hosting JSP page. This tag allows you to use relative URL references, rather than a URL that is relative to the most recent requested resource. The <html:base/> tag has no body and supports two attributes:
  * target : Represents the target attribute of the HTML <base> tag (optional)
  * server : Identifies a server name to use in the href as opposed to the result of a call to request.getServerName() (optional)

Ques: 57 Describe the attributes of the <html:button/> tag in the HTML tag library defined in the Struts.
Ans: The <html:button/> tag is used to render an HTML <input> element with an input type of button. The <html:button/> tag has a body type of JSP and supports the following attributes: 
  * property : Identifies the name of the input field being processed. (required) 
  * accessKey : Identifies a keyboard character to be used to immediately move focus to the HTML element defined by using this tag. 
  * alt : Defines an alternate text string for this element. 
  * altKey : Defines a resource key (to be retrieved from a resource bundle) that references an alternate text string for this element. 
  * disabled : If set to true, causes this HTML input element to be disabled. The default values is false. 
  * indexed : If set to true, then the name of the HTML tag is rendered as propertyName[indesNumber]. The indexed attribute is valid only when the tag is using it is nested with a <logic:itereate/> tag.
Other attributes are:
onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, style, styleClass, styleId, tabindex, title, titleKey, value.

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>

struts interview questions


Ques: 37 How will you use the Tile layout in your struts application?
Ans: To use a Tile, You need to perform the following steps:
  * Import the Tiles taglib with the taglib directive.
  * Use tiles:insert tag to insert the Tile layout into the current page.
  * Use tile:put tag to pass string parameters.
  * Use tiles:put tag to pass parameter Tiles.

Ques: 38 How will you create the the JSP Tile definition?
Ans: Definitions specify default parameters for Tile layouts. You can create definitions in JSP or XML. To create a JSP Tile Definition, follow the following steps:
  * Import the Tiles tag library using the taglib directive.
  * Ensure that the definition is created only once using the logic:notPresent tag.
  *  Define the definition with the tiles:definition tag and pass the JSP that defines the Tile layout and the scope of the newly created definition.
  * Define the default parameters with the tiles:put tag.

Ques: 39 How will you use the the JSP Tile definition in your struts application?
Ans: To use a Tile definition, follow these steps:
  * Import the Tiles taglib with taglib directive.
  * Include the JSP page that creates the definition by using jsp:include.
  * Use the tiles:insert tag, but specify the definition bean name and scope instead of the Tile layout page.
  * Use the tiles:put attribute to specify the title and content but not header and footer parameters.

Ques: 40 Describe the scope of the Tile in the Struts application?
Ans: The Tiles framework defines an additional scope called Tile scope. Like page scope, Tile scope is more private than request scope. It allows the user of the Tile to pass arguments (called parameters) to the TIle. Like a display function, it makes the page callable.
Nested tiles do not share the same Tile scope as their parent. The Tile scope of the current Tile is saved before the nested Tile is displayed; after the nested Tile finishes, the parent's Tile scope is restored to the request.

Ques: 41 What is the difference between the jsp:include tag and tiles:insert tag?
Ans: The jsp:include tag allows you to call a page and pass it to request parameters (jsp:param); the tiles:insert tag is similar but more powerful. The tiles:insert allows you to call a page and pass it sub-pages (called Tiles) and attributes. Tile scope lets you pass variables that are available only to that Tile layout.
Ans:
Code Repetition is reduced

Use of Tiles reduce the code repetition to a great extent. Code repetition is bad but repetition of layout logic could be worst. Tiles also handle this issue. As you have layout templates based on which all the pages are combined, you don't need to repeat the code for layout. Other view components are also reusable and can be used in the same application at other places reducing the code repetition.
2. Low coupling between pages
Coupling is the degree of interactivity between two entities. It is always suggested to minimize coupling between unrelated classes, packages, and so on. Same principle is applied to view components. Tiles reduce the coupling between unrelated view components.
3. High layout control
Tiles provide great layout control by providing layout templates.
4. I18N support for locale-specific loading
5. Dynamic Page building
Pages are built dynamically in tiles. You can control the page view by configuring it through xml.
6. Elimination of duplicate and redundant information
Tiles eliminate the duplicate and redundant information in the configuration file by providing Tiles inheritance.
7. Central location for view components
Tiles save definition of all the components at one place (in tilesDef.xml) and hence can be modified easily when required.