Previous | Home | Next |
Q.1 How you will make available any Message Resources Definitions file to the Struts Framework Environment?
Answer: The Message Resources Definitions file is a 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" />
Answer: Here is the code of Action Class that returns the ActionForward object.
ExampleAction.java
import javax.servlet.http.*; 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 ExampleAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward("testAction"); } }
Answer: Following tag displays all the errors:
<html:errors/>
Q.3 How you will enable front-end validation based on the xml in validation.xml?
Answer: The <html:javascript> tag to allow front-end validation based on the xml in validation.xml.
Example:
<html:javascript formName="loginForm" dynamicJavascript="true" staticJavascript="true" />
generates the client side java script for the form "loginForm" as defined in the validation.xml file. The <html:javascript> when added in the jsp file generates the client site validation script.
Answer: The class org.apache.struts.action. RequestProcessor process the request from the controller. We can make a sublass of RequestProcessor with our own version and modify how the request is processed.
A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.
The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext() method is used to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.
Q.5 What are the uses of tiles-def.xml file, resourcebundle.properties file, validation.xml file?
Answer:
tiles-def.xml is an xml file used to configure tiles with the struts application. You can define the layout / header / footer / body content for your View.
resourcebundle.properties file is used to configure the message (error/ other messages) for the struts applications.
validation.xml is used to declare sets of validations that should be applied to FormBeans.
Answer: Struts is very robust framework and is being used extensively in the industry. But there are some disadvantages of the Struts:
- High Learning Curve Struts requires lot of efforts to learn and master it. For any small project less experience developers could spend more time on learning the Struts.
- Harder to learn Struts are harder to learn, benchmark and optimize.
Answer:
<bean:message>: This tag is used to output locale-specific text (from the properties files) from a MessageResources bundle.
<bean:write>: This tag is used to output property values from a bean. <bean:write> is a commonly used tag which enables the programmers to easily present the data.
Previous | Home | Next |