|
What is Struts The core of the Struts framework is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Commons packages. Struts encourage application architectures based on the Model 2 approach, a variation of the classic Model-View-Controller (MVC) design paradigm. (Or) Struts provide its own Controller component and integrate with other technologies to provide the Model and the View. For the Model, Struts can interact with standard data access technologies, like JDBC and EJB, as well as most any third-party packages, like Hibernate, iBATIS, or Object Relational Bridge. For the View, Struts works well with JavaServer Pages, including JSTL and JSF, as well as Velocity Templates, XSLT, and Other presentation systems. (Or) The Struts framework provides the invisible underpinnings every professional web application needs to survive. Struts helps you create an extensible development environment for your application, based on published standards and proven design patterns. What is the difference between Struts 1.0 and Struts 1.1? The new features added to Struts 1.1 are 1. RequestProcessor class 2. Method perform() replaced by execute() in Struts base Action Class 3. Changes to web.xml and struts-config.xml 4.Declarative exception handling 5.Dynamic ActionForms 6.Plug-ins 7.Multiple Application Modules 8.Nested Tags 9.The Struts Validator 10.Change to the ORO package 11.Change to Commons logging 12.Removal of Admin actions 13. Deprecation of the GenericDataSource Explain Struts navigation flow? A client requests a path that matches the Action URI pattern. The container passes the request to the ActionServlet. If this is a modular application, the ActionServlet selects the appropriate module. The ActionServlet looks up the mapping for the path. If the mapping specifies a form bean, the ActionServlet sees if there is one already or creates one. If a form bean is in play, the ActionServlet resets and populates it from the HTTP request. If the mapping has the validate property set to true, it calls validate on the form bean. If it fails, the servlet forwards to the path specified by the input property and this control flow ends. If the mapping specifies an Action type, it is reused if it already exists or instantiated. The Action’s perform or execute method is called and passed the instantiated form bean (or null). The Action may populate the form bean, call business objects, and do whatever else is needed. The Action returns an ActionForward to the ActionServlet. If the ActionForward is to another Action URI, we begin again; otherwise, it’s off to a display page or some other resource. Most often, it is a JSP, in which case Jasper, or the equivalent (not Struts), renders the page. What is the difference between ActionForm and DynaActionForm? In struts 1.0; action form is used to populate the html tags in jsp using struts custom tag. When the java code changes, the change in action class is needed. To avoid the chages in struts 1.1 dyna action form is introduced. This can be used to develop using xml. The dyna action form bloats up with the struts-config.xml based definetion. What is DispatchAction? The DispatchAction class is used to group related actions into one class. DispatchAction is an abstract class, so you must override it to use it. It extends the Action class. It should be noted that you don’t have to use the DispatchAction to group multiple actions into one Action class. You could just use a hidden field that you inspect to delegate to member() methods inside of your action. How to call ejb from Struts? Use the Service Locator patter to look up the ejbs. Or you can use InitialContext and get the home interface. What are the various Struts tag libraries? Struts-html tag library - used for creating dynamic HTML user interfaces and forms. struts-bean tag library - provides substantial enhancements to the basic capability provided by . struts-logic tag library - can manage conditional generation of output text, looping over object collections for repetitive generation of output text, and application flow management. Struts-template tag library - contains tags that are useful in creating dynamic JSP templates for pages that share a common format. What is the difference between ActionErrors and ActionMessages? The difference between the classes is zero -- all behavior in ActionErrors was pushed up into ActionMessages and all behavior in ActionError was pushed up into ActionMessage. This was done in the attempt to clearly signal that these classes can be used to pass any kind of messages from the controller to the view -- errors being only one kind of message How you will handle errors and exceptions using Struts? How you will save the data across different pages for a particular client request-using Strut? Several ways. The similar to the ways session tracking is enabled. Using cookies, URL-rewriting, SSLSession, and possibilty threw in the database. If the request has a Form object, the data may be passed on through the Form object across pages. Or within the Action class, call request.getSession and use session.setAttribute(), though that will persist through the life of the session until altered. What we will define in Struts-config.xml file. And explain their purpose? The main control file in the Struts framework is the struts-config.xml XML file, where action mappings are specified. This file's structure is described by the struts-config DTD file, which is defined at http://jakarta.apache.org/struts/. A copy of the DTD can be found on the /docs/dtds subdirectory of the framework's installation root directory. The top-level element is struts-config. Basically, it consists of the following elements: data-sources:A set of data-source elements, describing parameters needed to instantiate JDBC 2.0 Standard Extension DataSource objects form-beans:A set of form-bean elements that describe the form beans that this application uses global-forwards:A set of forward elements describing general available forward URIs action-mappings:A set of action elements describing a request-to-action mapping What is the purpose of tiles-def.xml file, resourcebundle.properties file, and validation.xml file? The Tiles Framework is an advanced version of that comes bundled with the Struts Webapp framework. Its purpose is reduce the duplication between jsp pages as well as make layouts flexible and easy to maintain. It integrates with Struts using the concept of named views or definitions. What is Action Class? What are the methods in Action class? An Action is an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request. The controller (RequestProcessor) will select an appropriate Action for each request, create an instance (if necessary), and call the execute method. Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind: Instance and static variables MUST NOT be used to store information related to the state of a particular request. They MAY be used to share global resources across requests for the same action. Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary. When an Action instance is first created, the controller will call setServlet with a non-null argument to identify the servlet instance to which this Action is attached. When the servlet is to be shut down (or restarted), the setServlet method will be called with a null argument, which can be used to clean up any allocated resources in use by this Action. Action class is request handler in Struts. We will extend the Action class and over ride the execute() method in which we will specify the business logic to be performed. Explain about token feature in Struts? What part of MVC does Struts represent? |