tag:blogger.com,1999:blog-79764677320842263362024-03-06T01:04:23.096+05:30Mohan's StrutsBookStruts Interview QuestionsUnknownnoreply@blogger.comBlogger136125tag:blogger.com,1999:blog-7976467732084226336.post-70485841203721758522013-07-24T23:11:00.003+05:302013-07-24T23:11:45.026+05:30What is ActionMapping Class in Struts ?<div class=Section1> <p class=MsoNormal>ActionMappings is a collection of ActionMapping objects<o:p></o:p></p> <p class=MsoNormal>The ActionMapping contains the knowledge of how a specific event maps to specific Actions.<o:p></o:p></p> <p class=MsoNormal>The ActionServlet (Command) passes the ActionMapping to the Action class via the perform() method.<o:p></o:p></p> <p class=MsoNormal>This allows Action to access the information to control flow.<o:p></o:p></p> <p class=MsoNormal>The struts-config.xml determines what Action class the Controller calls.<o:p></o:p></p> <p class=MsoNormal>The struts-config.xml configuration information is translated into a set of ActionMapping, which are put into container of ActionMappings.<o:p></o:p></p> <p class=MsoNormal>Classes that end with s are containers.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-47112981008823318242013-07-24T23:11:00.001+05:302013-07-24T23:11:17.184+05:30What are the Validator Built-in Rules in Struts ?<div class=Section1> <p class=MsoNormal>required : field data provided<o:p></o:p></p> <p class=MsoNormal>minlength : more than min length<o:p></o:p></p> <p class=MsoNormal>maxlength : less than max length<o:p></o:p></p> <p class=MsoNormal>range : in range of values<o:p></o:p></p> <p class=MsoNormal>mask : correct format (takes regexp)<o:p></o:p></p> <p class=MsoNormal>date : validates correct date format<o:p></o:p></p> <p class=MsoNormal>email : validates correct E-Mail fromat<o:p></o:p></p> <p class=MsoNormal>primitives: byte, integer, float, double, etc.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-74460443732561661512013-07-24T23:10:00.001+05:302013-07-24T23:10:36.541+05:30How to prevent multi-click using struts tokens ?<div class=Section1> <p class=MsoNormal>Mutli-click prevention using struts tokens- Prevent Duplicate Submission :<o:p></o:p></p> <p class=MsoNormal>saveToken() : generate the token key and save to request/session attribute. <o:p></o:p></p> <p class=MsoNormal>isTokenValid() : validate submitted token key against the 1 store in request/session.<o:p></o:p></p> <p class=MsoNormal>resetToken() : reset the token key<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Follow the steps to setup Mutli-click prevention using struts tokens. <o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Step 1: Action Class where saveToken() before JSP Page <o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>First saveToken() then forward to your jsp. <o:p></o:p></p> <p class=MsoNormal>Upon loading the form, invokes saveToken() on the action class to create and store the token key. <o:p></o:p></p> <p class=MsoNormal>Struts will store the generated key in request/session.<o:p></o:p></p> <p class=MsoNormal>public class LoadAction extends Action <o:p></o:p></p> <p class=MsoNormal>{<o:p></o:p></p> <p class=MsoNormal>public ActionForward execute(ActionMapping mapping,ActionForm form,<o:p></o:p></p> <p class=MsoNormal>HttpServletRequest request,HttpServletResponse response)<o:p></o:p></p> <p class=MsoNormal>{ ActionForward forward;<o:p></o:p></p> <p class=MsoNormal>saveToken(request);<o:p></o:p></p> <p class=MsoNormal>forward=mapping.findForward("empformpage");<o:p></o:p></p> <p class=MsoNormal>// this is the jsp page where you want to struts tokens.<o:p></o:p></p> <p class=MsoNormal>return forward;<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal>Step 2:Store Token key as a hidden field ( empform.jsp) <o:p></o:p></p> <p class=MsoNormal>In the browser if you type : http://localhost:8080/testApp/loadActio.do <o:p></o:p></p> <p class=MsoNormal>This will call execute() method of LoadAction. Then saveToken(request);//create and store the token key and mapping.findForward("empformpage"); forward to empform.jsp (below code is for empform.jsp) <o:p></o:p></p> <p class=MsoNormal><%@ page import="org.apache.struts.action.Action"%><o:p></o:p></p> <p class=MsoNormal><%@ page import="org.apache.struts.taglib.html.Constants"%><o:p></o:p></p> <p class=MsoNormal><%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %><o:p></o:p></p> <p class=MsoNormal><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><o:p></o:p></p> <p class=MsoNormal><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><o:p></o:p></p> <p class=MsoNormal><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Save<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Step 3. Check Token is Valid ?<o:p></o:p></p> <p class=MsoNormal>Once the form submitted, invokes isTokenValid() on the action class, it will validate the submitted token key(hidden field) with the token key stored previously on request/session. If match, it will return true. <o:p></o:p></p> <p class=MsoNormal>public class SubmitAction extends Action<o:p></o:p></p> <p class=MsoNormal>{<o:p></o:p></p> <p class=MsoNormal>public ActionForward execute(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,<o:p></o:p></p> <p class=MsoNormal>HttpServletResponse response)<o:p></o:p></p> <p class=MsoNormal>{<o:p></o:p></p> <p class=MsoNormal>EmpForm frm=(EmpForm)form;<o:p></o:p></p> <p class=MsoNormal>if(isTokenValid(request))<o:p></o:p></p> <p class=MsoNormal>{ // This is Not Duplicate Submission of the form<o:p></o:p></p> <p class=MsoNormal>// You can add your logic here <o:p></o:p></p> <p class=MsoNormal>resetToken(request);<o:p></o:p></p> <p class=MsoNormal>return mapping.findForward("sucess");<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal>else<o:p></o:p></p> <p class=MsoNormal>{ // This is Duplicate Submission of the form<o:p></o:p></p> <p class=MsoNormal>// Return to the JSP to display the error message ( This is Duplicate Submission);<o:p></o:p></p> <p class=MsoNormal>return mapping.findForward("duplicatesubmitpage");<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-44329835919696065292013-07-24T23:09:00.003+05:302013-07-24T23:09:48.279+05:30Differences between web.xml and sturts-config.xml ?<div class=Section1> <p class=MsoNormal>web.xml :<o:p></o:p></p> <p class=MsoNormal>It is used for the deployment descriptor for web applications<o:p></o:p></p> <p class=MsoNormal>web.xml is used for making connection between web container & web application<o:p></o:p></p> <p class=MsoNormal>It is read by container when we start the container.<o:p></o:p></p> <p class=MsoNormal>sturts-config.xml :<o:p></o:p></p> <p class=MsoNormal>It is used for deployment descripror for struts application.<o:p></o:p></p> <p class=MsoNormal>It is used for making connection between view & controller<o:p></o:p></p> <p class=MsoNormal>It is read by init() method of ActionServlet.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-56384408760618273922013-07-24T23:09:00.001+05:302013-07-24T23:09:34.033+05:30Explain life cycle of ActionForm ?<div class=Section1> <p class=MsoNormal>The lifecycle of ActionForm invoked by the RequestProcessor is as follows:<o:p></o:p></p> <p class=MsoNormal>Retrieve or Create Form Bean associated with Action<o:p></o:p></p> <p class=MsoNormal>"Store" FormBean in appropriate scope (request or session)<o:p></o:p></p> <p class=MsoNormal>Reset the properties of the FormBean <o:p></o:p></p> <p class=MsoNormal>Populate the properties of the FormBean<o:p></o:p></p> <p class=MsoNormal>Validate the properties of the FormBean<o:p></o:p></p> <p class=MsoNormal>Pass FormBean to Action<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-84949173006666004922013-07-24T23:08:00.001+05:302013-07-24T23:08:27.471+05:30What are the different types of Actions available in Struts ?<div class=Section1> <p class=MsoNormal>DispatchAction:<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>One of the built-in actions provided by the struts framework. The collection of related functions into a single Action is possible using this action. It allows eliminating the creation of multiple independent actions for each function.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>ActionDispatcher:<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>It is a helper class which dispatches to a method that is in Action. This class provides an alternative mechanism for using DispatchAction. With the help of various types of mechanisms, the ‘dispatching’ behavior can be easily implemented into an Action without inheritance of a particular super Action class.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>LookupDispatchAction:<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>The subclass mapped execute() method is dispatched by this abstract Action class. This process is useful where a HTML form has many clicks on submit buttons with the same name. The corresponding ActionMapping’s parameter property specifies the button name.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Forward Action and IncludeAction:<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>These forward and include the context-relative URI specified by the parameter property of our associated ActionMapping.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-76464925412148447952013-07-24T23:07:00.000+05:302013-07-24T23:08:06.881+05:30What is the difference between perform() and execute() methods ?<div class=Section1> <p class=MsoNormal>Perform method is the method which was deprecated in the Struts Version 1.1. In Struts 1.x, Action.perform() is the method called by the ActionServlet. <o:p></o:p></p> <p class=MsoNormal>This is typically where your business logic resides, or at least the flow control to your JavaBeans and EJBs that handle your business logic.<o:p></o:p></p> <p class=MsoNormal>As we already mentioned, to support declarative exception handling, the method signature changed in perform. <o:p></o:p></p> <p class=MsoNormal>Now execute just throws Exception. Action.perform() is now deprecated; however, the Struts v1.1 ActionServlet is smart enough to know whether or not it should call perform or execute in the Action, depending on which one is available.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-25048071518388970282013-07-24T23:06:00.003+05:302013-07-24T23:06:26.322+05:30Is struts threadsafe ?<div class=Section1> <p class=MsoNormal>Struts is not only thread-safe but thread-dependant. The response to a request is handled by a light-weight Action object, rather than an individual servlet. Struts instantiates each Action class once, and allows other requests to be threaded through the original object.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-11134882862397235952013-07-24T23:06:00.001+05:302013-07-24T23:06:09.688+05:30How RequestProcessor decides that validation is success or fail ?<div class=Section1> <p class=MsoNormal>Based on ActionErrors instance returned by Formbean java class validate().<o:p></o:p></p> <p class=MsoNormal>The action form class provides a method validate() which is called before the action class is executed. So you can validate your properties within this method. The return-value of the method is a collection (ActionErrors) of error messages (ActionMessage).<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-87763930187077681112013-07-24T23:05:00.001+05:302013-07-24T23:05:53.548+05:30What is the difference between ActionForm and DynaActionForm ?<div class=Section1> <p class=MsoNormal>ActionForm will populate the properties depending on the respective JSP fields.In this we can specify the validate() method (if required) for validations or else you can use ActionErrors for validating.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>DynaActionForm has to be defined in Struts-config.xml and it may have many property fields. We can use this form for many no.of JSPs. Single dynaActionForm can serve for many number of JSPs.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-48123166662393850732013-07-24T23:02:00.001+05:302013-07-24T23:02:14.765+05:30How to get data from the velocity page in a action class?<div class=Section1> <p class=MsoNormal>We can get the values in the action classes by using data.getParameter(\"variable name defined in the velocity page\");<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-5460556877472783932013-07-24T23:01:00.001+05:302013-07-24T23:01:11.710+05:30Explain about token feature in Struts ?<div class=Section1> <p class=MsoNormal>Use the Action Token methods to prevent duplicate submits:<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>There are methods built into the Struts action to generate one-use tokens. A token is placed in the session when a form is populated and also into the HTML form as a hidden property. When the form is returned, the token is validated. If validation fails, then the form has already been submitted, and the user can be apprised.<o:p></o:p></p> <p class=MsoNormal>saveToken(request)<o:p></o:p></p> <p class=MsoNormal>on the return trip,<o:p></o:p></p> <p class=MsoNormal>isTokenValid(request)<o:p></o:p></p> <p class=MsoNormal>resetToken(request) <o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-15200617651793514702013-07-24T23:00:00.003+05:302013-07-24T23:00:52.467+05:30How you will enable front-end validation based on the xml in validation.xml ?<div class=Section1> <p class=MsoNormal>The <html:javascript> tag to allow front-end validation based on the xml in validation.xml. For example the code: <o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><html:javascript formName=\"logonForm\" dynamicJavascript=\"true\" staticJavascript=\"true\" /> <o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>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.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-43884869977782410232013-07-24T23:00:00.001+05:302013-07-24T23:00:28.193+05:30How you will display validation fail errors on jsp page ?<div class=Section1> <p class=MsoNormal>Following tag displays all the errors:<o:p></o:p></p> <p class=MsoNormal><html:errors/><o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-47916620590942322552013-07-24T22:54:00.002+05:302013-07-24T22:55:10.796+05:30Give the Details of XML files used in Validator Framework?<div class=Section1> <p class=MsoNormal>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.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-29048762327377279632013-07-24T22:54:00.001+05:302013-07-24T22:54:49.680+05:30What is the difference between DynaActionForm and DynaValidatorForm?<div class=Section1> <p class=MsoNormal>Specialized subclass of ActionForm that allows the creation of form beans with dynamic sets of properties, without requiring the developer to create a Java class for each type of form bean.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>This class extends DynaActionForm and provides basic field validation based on an XML file. The key passed into the validator is the action element's 'name' attribute from the struts-config.xml which should match the form element's name attribute in the validation.xml.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-60829689766910129422013-07-24T22:50:00.002+05:302013-07-24T22:51:09.673+05:30What is Struts Validator Framework ?<div class=Section1> <p class=MsoNormal>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.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>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.<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-77886199689020251732013-07-24T22:50:00.001+05:302013-07-24T22:50:23.535+05:30What is DispatchAction ?<div class=Section1> <p class=MsoNormal>Basically Dispatch action is used when you have multiple submit buttons in a single form.The Dispatch action is a class which extends the Struts DispatchAction , and encpsulates all the action methods (similar to execute method in Action class)in one single class.These actions methods will get executed based on the parameter that you pass in a jsp page.In the Struts-Config.xml you need to define the DispatchAction class and the parameter name that you passing in the URL.Based on the parameter the Controller will invoke the action method.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>struts-config.xml<o:p></o:p></p> <p class=MsoNormal>parameter – attribute is used to delegate the request to corresponding method of the BookAction class. So define this value with appropriate name.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>BookAction.java<o:p></o:p></p> <p class=MsoNormal>It eliminates the execute method entirely. Because it directly implements the desired methods, those custom methods have same signature as execute method.<o:p></o:p></p> <p class=MsoNormal>The class BookAction extends org.apache.struts.actions.DispatchAction<o:p></o:p></p> <p class=MsoNormal>import org.apache.struts.action.ActionForm;<o:p></o:p></p> <p class=MsoNormal>import org.apache.struts.action.ActionMapping;<o:p></o:p></p> <p class=MsoNormal>import org.apache.struts.action.ActionForward;<o:p></o:p></p> <p class=MsoNormal>import javax.servlet.http.HttpServletRequest;<o:p></o:p></p> <p class=MsoNormal>import javax.servlet.http.HttpServletResponse;<o:p></o:p></p> <p class=MsoNormal>import org.apache.struts.actions.DispatchAction;<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>public class BookAction extends DispatchAction<o:p></o:p></p> <p class=MsoNormal>{<o:p></o:p></p> <p class=MsoNormal>public ActionForward addBook(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {<o:p></o:p></p> <p class=MsoNormal>System.out.println("Add Book Page");<o:p></o:p></p> <p class=MsoNormal>return mapping.findForward("addBook");<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>public ActionForward editBook(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {<o:p></o:p></p> <p class=MsoNormal>System.out.println("Edit Book Page");<o:p></o:p></p> <p class=MsoNormal>return mapping.findForward("editBook");<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>public ActionForward saveBook(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {<o:p></o:p></p> <p class=MsoNormal>System.out.println("Save Book Page");<o:p></o:p></p> <p class=MsoNormal>return mapping.findForward("saveBook");<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>public ActionForward deleteBook(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {<o:p></o:p></p> <p class=MsoNormal>System.out.println("Delete Book Page");<o:p></o:p></p> <p class=MsoNormal>return mapping.findForward("deleteBook");<o:p></o:p></p> <p class=MsoNormal>}<o:p></o:p></p> <p class=MsoNormal>} <o:p></o:p></p> <p class=MsoNormal>bookdetails.jsp<o:p></o:p></p> <p class=MsoNormal>This page has four different links for doing different actions say Add/Edit/Save/Delete books. Every individual action has to be uniquely represented by the request parameter actionMethod.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-66552690392292793372013-07-24T22:49:00.000+05:302013-07-24T22:50:18.293+05:30What is IncludeAction ?<div class=Section1> <p class=MsoNormal>An Action that includes the context-relative URI specified by the parameter property of our associated ActionMapping. This can be used to integrate Struts with other business logic components that are implemented as servlets (or JSP pages), but still take advantage of the Struts controller servlet's functionality<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><action name="log" <o:p></o:p></p> <p class=MsoNormal>parameter="/WEB-INF/classes/com/struts/ser/ShowServlet" <o:p></o:p></p> <p class=MsoNormal>path="/logs1" <o:p></o:p></p> <p class=MsoNormal>type="org.apache.struts.actions.IncludeAction"><o:p></o:p></p> <p class=MsoNormal></action><o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-5777569765063666462013-07-24T22:48:00.000+05:302013-07-24T22:49:06.964+05:30What is ForwardAction ?<div class=Section1> <p class=MsoNormal>The struts framework ForwardAction class provides a mechanism for forwarding to a specified URL. In an MVC Web application, all requests to the application are supposed to flow through the Controller servlet. <o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>This will ensure that the Controller layer of the application has an opportunity to prepare any resources that may be needed to handle the request meaning selecting the correct module and so on. The struts framework ForwardAction is provided as a simple utility action that can be used for scenarios in which you simply want to link to a JSP page.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Example:<o:p></o:p></p> <p class=MsoNormal> <o:p></o:p></p> <p class=MsoNormal><action parameter="/Welcome.jsp" <o:p></o:p></p> <p class=MsoNormal> path="/Welcome" <o:p></o:p></p> <p class=MsoNormal> type="org.apache.struts.actions.ForwardAction"><o:p></o:p></p> <p class=MsoNormal></action><o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-13995390602191560622013-07-24T22:46:00.003+05:302013-07-24T22:56:41.634+05:30What is ActionForm ?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="Section1">
<div class="MsoNormal">
An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm.<o:p></o:p></div>
<div class="MsoNormal">
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.</div>
<div>
<br /></div>
</div>
</div>
Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-20635565352333153422013-07-24T22:46:00.001+05:302013-07-24T22:46:35.423+05:30How is the MVC design pattern used in Struts framework?<div class=Section1> <p class=MsoNormal>The Struts Framework is a standard for developing well-architected Web applications. It has the following features:<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Based on the Model-View-Controller (MVC) design paradigm, distinctly separating all three levels:<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Model: application state<o:p></o:p></p> <p class=MsoNormal>View: presentation of data (JSP, HTML)<o:p></o:p></p> <p class=MsoNormal>Controller: routing of the application flow<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>1. Model Tier :<o:p></o:p></p> <p class=MsoNormal>Struts includes only minimal infrastructure for the model tier<o:p></o:p></p> <p class=MsoNormal>A basic implementation of javax.sql.DataSource is included<o:p></o:p></p> <p class=MsoNormal>But you can integrate any desired approach<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>2. View Tier :<o:p></o:p></p> <p class=MsoNormal> Form Beans:<o:p></o:p></p> <p class=MsoNormal>Represent the server side state of the input fields on an HTML form<o:p></o:p></p> <p class=MsoNormal>Contains hooks for resetting fields to default values (needed for checkboxes) and input field validation<o:p></o:p></p> <p class=MsoNormal>DynaActionForm means you do not have to create new JavaBeans yourself<o:p></o:p></p> <p class=MsoNormal>Validation Framework:<o:p></o:p></p> <p class=MsoNormal>Abstract input validation rules into separate XML document<o:p></o:p></p> <p class=MsoNormal>Extensible for custom field checking<o:p></o:p></p> <p class=MsoNormal>Optionally generates client-side JavaScript<o:p></o:p></p> <p class=MsoNormal>Always checks on server side<o:p></o:p></p> <p class=MsoNormal>Integrated with standard ActionForm beans and DynaActionForm beans<o:p></o:p></p> <p class=MsoNormal>(JSP) Custom Tag Libraries:<o:p></o:p></p> <p class=MsoNormal>Bean – General purpose bean and property manipulation<o:p></o:p></p> <p class=MsoNormal>Html – Dynamic HTML-based user interfaces (including input forms)<o:p></o:p></p> <p class=MsoNormal>Logic – Conditionals and iteration<o:p></o:p></p> <p class=MsoNormal>Nested – Versions of other tags that access nested JavaBean hierarchies easily<o:p></o:p></p> <p class=MsoNormal>Tiles – Layout management (next page)<o:p></o:p></p> <p class=MsoNormal>(JSP) Tiles Framework:<o:p></o:p></p> <p class=MsoNormal>Supports templating for common look and feel of all pages in a web app<o:p></o:p></p> <p class=MsoNormal>Tile definitions created in JSP page or in external XML document<o:p></o:p></p> <p class=MsoNormal>Definitions can extend base definitions<o:p></o:p></p> <p class=MsoNormal>Advanced techniques for dynamically passing information to tiles<o:p></o:p></p> <p class=MsoNormal>3. Controller Tier :<o:p></o:p></p> <p class=MsoNormal>Configuration Document Defines Behavior<o:p></o:p></p> <p class=MsoNormal>Action URLs mapped to Actions<o:p></o:p></p> <p class=MsoNormal>Data sources<o:p></o:p></p> <p class=MsoNormal>Exception handlers<o:p></o:p></p> <p class=MsoNormal>Form beans<o:p></o:p></p> <p class=MsoNormal>Forwarding URLs mapped to Pages<o:p></o:p></p> <p class=MsoNormal>Message Resources for i18n<o:p></o:p></p> <p class=MsoNormal>PlugIns for Lifecycle Management<o:p></o:p></p> <p class=MsoNormal>One or more documents allowed<o:p></o:p></p> <p class=MsoNormal>Request Processing Lifecycle :<o:p></o:p></p> <p class=MsoNormal>Extract action mapping path<o:p></o:p></p> <p class=MsoNormal>Select locale (if necessary)<o:p></o:p></p> <p class=MsoNormal>Select action mapping to utilize<o:p></o:p></p> <p class=MsoNormal>Perform role-based access checks<o:p></o:p></p> <p class=MsoNormal>Server-side validation (if requested)<o:p></o:p></p> <p class=MsoNormal>Invoke application Action<o:p></o:p></p> <p class=MsoNormal>Forward based on application outcome<o:p></o:p></p> <p class=MsoNormal>Highly customizable and extendable<o:p></o:p></p> <p class=MsoNormal>Sub-Application Modules :<o:p></o:p></p> <p class=MsoNormal>Logically divide single web application into multiple Struts “mini-applications”<o:p></o:p></p> <p class=MsoNormal>Session state shared across all modules<o:p></o:p></p> <p class=MsoNormal>Standard Action Implementations:<o:p></o:p></p> <p class=MsoNormal>Forward or include other URLs<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-24125551992949113022013-07-24T22:44:00.000+05:302013-07-24T22:45:12.354+05:30Explain Struts Workflow ?<div class=Section1> <p class=MsoNormal>A request comes in from a Java Server Page into the ActionServlet.<o:p></o:p></p> <p class=MsoNormal>The ActionServlet having already read the struts-config.xml file, knows which form bean relates to this JSP, and delegates work to the validate method of that form bean.<o:p></o:p></p> <p class=MsoNormal>The form bean performs the validate method to determine if all required fields have been entered, and performs whatever other types of field validations that need to be performed.<o:p></o:p></p> <p class=MsoNormal>If any required field has not been entered, or any field does not pass validation, the form bean generates ActionErrors, and after checking all fields returns back to the ActionServlet.<o:p></o:p></p> <p class=MsoNormal>The ActionServlet checks the ActionErrors that were returned from the form bean’s validate method to determine if any errors have occurred. If errors have occurred, it returns to the originating JSP displaying the appropriate errors.<o:p></o:p></p> <p class=MsoNormal>If no errors occurred in the validate method of the form bean, the ActionServlet passes control to the appropriate Action class.<o:p></o:p></p> <p class=MsoNormal>The Action class performs any necessary business logic, and then forwards to the next appropriate action (probablyanother JSP).<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-33128485067897387732013-07-24T22:31:00.003+05:302013-07-24T22:31:30.968+05:30Explain about Struts Config File (struts-config.xml) ?<div class=Section1> <p class=MsoNormal>struts-config.xml contains three important elements used to describe actions: <o:p></o:p></p> <p class=MsoNormal><form-beans> contains FormBean definitions including name and type (classname)<o:p></o:p></p> <p class=MsoNormal><action-mapping> contains action definitions<o:p></o:p></p> <p class=MsoNormal>Use an <action> element for each action defined<o:p></o:p></p> <p class=MsoNormal><global-forwards> contains your global forward definitions<o:p></o:p></p> </div> Unknownnoreply@blogger.comtag:blogger.com,1999:blog-7976467732084226336.post-84681497073118889432013-07-24T22:31:00.001+05:302013-07-24T22:31:26.257+05:30What is the "global-forwards" in Struts Config File ?<div class=Section1> <p class=MsoNormal>Forwards are instances of the ActionForward class returned from an ActionForm's execute method.These map logical names to specific resources (typically JSPs) <forward> element has following attributes. <o:p></o:p></p> <p class=MsoNormal>name: logical name of the forward used within execute() method of Action class to forward to the next resource<o:p></o:p></p> <p class=MsoNormal>path: to-be-forwarded resource<o:p></o:p></p> <p class=MsoNormal>redirect: redirect (true) or forward (false)<o:p></o:p></p> </div> Unknownnoreply@blogger.com