Q.What is Jakarta Struts Framework? A.Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.An open source framework for creating web applications. Web applications, some deliver static content and some create dynamic response. A web application can perform database actions and perform business logic to make responses customized.A web application that uses JSP sometimes mix the operations like database code, design code, and control code. In this way a web application becomes difficult to maintain.Model, View, Control(MVC) architecture is one of the ways to separate the concerns in developing software applications. The struts framework is designed to isolate these process (MVC architecture) while designing web applications. The struts framework provides the key components for a web applicatons such as: 1.A “request” is being handled by the request handler which is developed by application developer which is mapped to a standard URI. 2.A “response” handler – transferring the control from one resource to another that finishes the process of response. 3.A tag library – which is used to create interactive form-based applications by the developers with server pages. 4.Struts also works well with the conventional applications with SOAP and AJAX. Q.Describe the components of Struts A.Struts components: 1.Model Components:Many application’s focus is on the view. The processing required for each submitted form / request by keeping the model’s perspective in view. In general the focus for handling the model components is done by the creation of java beans that support the functionality requirements. The scope concept is related to the beans is used first.The concept of extending ActionForm class is assumed by the Struts framework for each input form. ActionForm is a bean that are declared in ActionMapping configurationfile. The struts controller servlet automatically performs the services required, before invoking the appropriate Action method. 2.View Components: Struts supports the interacting input forms and used for building internationalized applications. Some files are uploaded by using HTML forms. Most of the browsers support the uploading of files through a input tag like . This generates a file browse button. Struts handles these kind of forms in a way that is identical to building normal forms. 3.Controller Components: The primary function of mapping request URI to an Action class that is implemented by the servlet. This operation also included in Struts framework. So, the Controller responsibilities include: 1.Write an Action class for every request that may be received. 2.Configuring an ActionMapping, that is in the form of XML file, for every logical requests that implements. The name of the file is struts-config.xml 3.Updating the deployment descriptor file for the application to include the necessary components. 4.Adding the Struts components to the application. Q.Explain the core classes of the Struts Framework A.The core classes of Struts framework are:ActionServlet, ActionForm, Action, Action Mapping, ActionForward Q.How you will make available any Message Resources Definitions file to the Struts Framework Environment? A.Message Resources Definitions file are 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 tag. Example: 4.Give the Details of XML files used in Validator Framework? A.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. Q.How you will display validation fail errors on jsp page? A.The following tag displays all the errors: Q.How you will enable front-end validation based on the xml in validation.xml? A.The tag to allow front-end validation based on the xml in validation.xml. For example the code: generates the client side java script for the form “logonForm” as defined in the validation.xml file. The when added in the jsp file generates the client site validation script. Q.How is the MVC design pattern used in Struts framework? A.In the MVC design pattern, application flow is mediated by a central Controller. The Controller delegates requests to an appropriate handler. The handlers are tied to a Model, and each handler acts as an adapter between the request and the Model. The Model represents, or encapsulates, an application's business logic or state. Control is usually then forwarded back through the Controller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. This provides a loose coupling between the View and Model, which can make an application significantly easier to create and maintain. 1.Controller--Servlet controller which supplied by Struts itself; 2.View --- what you can see on the screen, a JSP page and presentation components; 3.Model --- System state and a business logic JavaBeans. Q.Who makes the Struts? A.Struts is hosted by the Apache Software Foundation(ASF) as part of its Jakarta project, like Tomcat, Ant and Velocity. Q.Why it called Struts? A.Because the designers want to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and ourselves when we are on stilts. This excellent description of Struts reflect the role the Struts plays in developing web applications. Q.Do we need to pay the Struts if being used in commercial purpose? A.No. Struts is available for commercial use at no charge under the Apache Software License. You can also integrate the Struts components into your own framework just as if they were written in house without any red tape, fees, or other hassles. Q.What is the design role played by Struts? A.The role played by Structs is controller in Model/View/Controller(MVC) style. The View is played by JSP and Model is played by JDBC or generic data source classes. The Struts controller is a set of programmable components that allow developers to define exactly how the application interacts with the user. Q.How Struts control data flow? A.Struts implements the MVC/Layers pattern through the use of ActionForwards and ActionMappings to keep control-flow decisions out of presentation layer. Q.What configuration files are used in Struts? A. 1.ApplicationResources.properties 2.struts-config.xml These two files are used to bridge the gap between the Controller and the Model. Q.What helpers in the form of JSP pages are provided in Struts framework? A. 1.struts-html.tld 2.struts-bean.tld 3.struts-logic.tld Q.Is Struts efficient? A.The Struts is not only thread-safe but thread-dependent(instantiates each Action once and allows other requests to be threaded through the original object. ActionForm beans minimize subclass code and shorten subclass hierarchies. 1.The Struts tag libraries provide general-purpose functionality 2.The Struts components are reusable by the application 3.The Struts localization strategies reduce the need for redundant JSPs 4.The Struts is designed with an open architecture--subclass available 5.The Struts is lightweight (5 core packages, 5 tag libraries) 6.The Struts is open source and well documented (code to be examined easily) 7.The Struts is model neutral Q.How you will enable front-end validation based on the xml in validation.xml? A.The tag to allow front-end validation based on the xml in validation.xml. For example the code: generates the client side java script for the form logonForm as defined in the validation.xml file. The when added in the jsp file generates the client site validation script. Q.How you will make available any Message Resources Definitions file to the Struts Framework Environment? A.Message Resources Definitions file are 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 tag. Example: Q.Give the Details of XML files used in Validator Framework? A.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. How you will display validation fail errors on jsp page? - The following tag displays all the errors: Q.Why do we need Struts? A.Java technologies give developers a serious boost when creating and maintaining applications to meet the demands of today's public Web sites and enterprise intranets. Struts combines Java Servlets, Java ServerPages, custom tags, and message resources into a unified framework. The end result is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone in between. Q.How does Struts work? A.Java Servlets are designed to handle requests made by Web browsers. Java ServerPages are designed to create dynamic Web pages that can turn billboard sites into live applications. Struts uses a special Servlet as a switchboard to route requests from Web browsers to the appropriate ServerPage. This makes Web applications much easier to design, create, and maintain. Q.Is Struts compatible with other Java technologies? A.Yes. Struts is committed to supporting industry standards. Struts acts as an integrator of Java technologies so that they can be used in the "real world". Q.Who wrote Struts? A.There are several active committers to the Struts project, working cooperatively from around the globe. Dozens of individual developers and committers contributed to the Struts 1.x codebase. All interested Java developers are invited to contribute to the project. Struts is a Apache Software Foundation project, with the mission to "provide secure, enterprise-grade server solutions based on the Java Platform that are developed in an open and cooperative fashion". Q.Do I have to credit Struts on my own website? A.You need to credit Struts if you redistribute your own framework based on Struts for other people to use. (See the Apache License for details.) But you do not need to credit Struts just because your web application utilizes the framework. It's the same situation as using the Apache HTTPD server or Tomcat. Not required if its just running your web site. Q.Where can I get a copy of Struts? A.The best place to download Struts is at struts.apache.org. The nightly builds are very stable, and recommended as the best place to start today. Q.How do I install Struts? A.To develop applications with Struts, you can usually just add the Struts JAR file to your Java development environment. You can then start using the Struts classes as part of your own application. A blank Struts application (in the webapps directory, open struts-blank.war) is provided, which you can just copy to get a quick-start on your own brainchild.Since the full source code for Struts is available, we also provide complete instructions for compiling your own Struts JAR from scratch. (This is actually easier than it looks!) Your Struts application can usually be deployed using a standard WAR file. In most cases, you simply deposit the WAR file on your application server, and it is installed automatically. If not, step-by-step installation instructions for various servlet containers are available. Q.When do I need "struts.jar" on my classpath? A.When you are compiling an application that uses the Struts classes, you must have the "struts.jar" on the classpath your compiler sees -- it does not have to be on your CLASSPATH environment variable. Q.Why is that an important distinction? A.Because if you are using a servlet container on your development machine to test your application, the "struts.jar" must not be on your CLASSPATH environment variable when running the container. (This is because each Web application must also have their own copy of the Struts classes, and the container will become confused if it is on the environment path as well.) There are several general approaches to this issue: 1.Use ANT for building your projects -- it can easily assemble classpaths for the compiler. (This is how Struts itself is built, along with Tomcat and most other Java-based projects). 2.Use an IDE where you can configure the "class path" used for compilation independent of the CLASSPATH environment variable. 3.Use a shell script that temporarily adds struts.jar to the classpath just for compilation, for example javac -classpath /path/to/struts.jar:$CLASSPATH $@ Q.Does Struts include its own unit tests? A.Struts currently has two testing environments, to reflect the fact that some things can be tested statically, and some really need to be done in the environment of a running servlet container.For static unit tests, we use the JUnit framework. The sources for these tests are in the "src/test" hierarchy in the source repository, and are executed via the "test.junit" target in the top-level build.xml file. Such tests are focused on the low-level functionality of individual methods, are particularly suitable for the static methods in the org.apache.struts.util utility classes. In the test hierarchy, there are also some "mock object" classes (in the org.apache.struts.mock package) so that you can package up things that look like servlet API and Struts API objects to pass in as arguments to such tests. Another valuable tool is Struts TestCase which provides a useful harness for Action classes that can be used with JUnit or Cactus. Q.If the framework doesn't do what I want, can I request that a feature be added? A.First, it's important to remember that Struts is an all-volunteer project. We don't charge anyone anything to use Struts. Committers and other developers work on Struts because they need to use it with their own applications. If others can use it too, that's "icing on the cake". If you submit a patch for a feature that a Committer finds useful, then that Committer may choose to volunteer his or her time to apply the patch. If you just submit an idea without a patch, it is much less likely to be added . We are grateful for any patches, and we welcome new ideas, but the best way to see that something gets added to the framework is to do as much of the work as you can, rather than rely on the "kindness of strangers". Worst case, you can apply the patch to your copy of Struts and still use the feature in your own application. Q.Where can I get help with Struts? A.The Struts package comes complete with a Users Guide to introduce people to the framework and its underlying technologies. Various components also have their own in-depth Developers Guide, to cover more advanced topics. Comprehensive Javadocs are included along with the full source code. For your convenience, these are bundled together as a self-installing application. The struts-documentation.war is the same bundle that is deployed as the Struts Web site. The Strut's mailing list is also very active, and welcomes posts from new users. Before posting a new question, be sure to consult the MAILING LIST ARCHIVE and the very excellent How To Ask Questions The Smart Way by Eric Raymond. Please do be sure to turn off HTML in your email client before posting. Q.What's the difference between Struts and Turbine? What's the difference between Struts and Espresso? A.If you are starting from scratch, packages like Turbine and Espresso can be very helpful since they try to provide all of the basic services that your team is likely to need. Such services include things like data persistence and logging. If you are not starting from scratch, and need to hook up your web application to an existing infrastructure, then "plain vanilla" Struts can be a better choice. The core Struts framework does not presuppose that you are using a given set of data persistence, presentation, or logging tools. Anything goes =:0) Compared to other offerings, Struts endeavors to be a minimalist framework. We try leverage existing technologies whenever we can and provide only the missing pieces you need to combine disparate technologies into a coherent application. This is great when you want to select your own tools to use with Struts. But, if you prefer a more integrated infrastructure, then packages like Turbine or Espresso (which uses Struts) are perfectly good ways to go. Q.Why aren't the Struts tags maintained as part of the Jakarta Taglibs project ? A.Development of both products began about the same time. Leading up to the release of 1.0, it was thought better to continue to develop the taglibs alongside the controller. Now that 1.0 is out, the JavaServer Pages Standard Taglib is in active development. Once work on JSTL stabilizes, the Struts taglibs will be revisited. Tags which are not linked directly to the framework may be hosted at Jakarta Taglibs instead. Q.Are the Struts tags XHTML compliant ? A.If you use an or element on your page, the tags will render as XHTML (since Struts 1.1). Q.Will the Struts tags support other markup languages such as WML ? A.Struts itself is markup neutral. The original Struts taglibs are only one example of how presentation layer components can access the framework. The framework objects are exposed through the standard application, session, and request contexts, where any Java component in the application can make use of them. Markup extensions that use Struts are available for Velocity and XLST, among others. A new Struts tag library for Java Server Faces is also in development. For more about using WAP/WML with Struts see the article WAP up your EAserver. Q.What about JSTL and JavaServer Faces ? A.JSTL, the JavaServer Standard Tag Library, is a set of JSP tags that are designed to make it easier to develop Web applications. JavaServer Faces (JSF) is a specification for a new technology that promises to make it easier to write MVC applications, both for the Web and for the desktop. The inventor of Struts, Craig McClanahan, is the specification co-lead for JavaServer Faces (JSR 127), and architect of the reference implemenation as well as Java Studio Creator. Both JSTL and JSF are complementary to Struts. The mainstay of the Struts framework is the controller components, which can be used with any Java presentation technology. As new technologies become available, it is certain that new "glue" components will also appear to help these technologies work as well with Struts. Struts originally came bundled with a set of custom JSP tags. Today, several extensions are available to help you use Struts with other popular presentation technologies, like XSLT and Velocity. Likewise, extensions for JSTL and JSF are now available as well. The JSTL reference implementation is available through the Jakarta Taglibs site. A JSTL taglibs for Struts, Struts-El , is available and distributed with Struts beginning with the 1.1 release. The JSF specification and reference implementation is available through Sun's The JSF specification and reference implementation is available through Sun's Java ServerFaces page. An early-release JavaServer Faces taglib for Struts, Struts-Faces, is also in early release and available through the nightly build. The Struts Faces taglib is expected to work with any compliant JSF implementation, including MyFaces. Q.Is there a particularly good IDE to use with Struts A.Struts should work well with any development environment that you would like to use, as well as with any programmers editor. The members of the Struts development team each use their own tools such as Emacs, IDEA, Eclipse, and NetBeans. Q.Why was reload removed from Struts (since 1.1)? A.The problem with ReloadAction was that Struts was trying to act like a container, but it couldn't do a proper job of it. For example, you can't reload classes that have been modified, or (portably) add new classes to a running web application (even if the container supported it). Meanwhile, as Struts 1.1 was being developed, work progressed on things like Tomcat's reload command via the Manager webapp. This feature allows you to quickly reload-on-demand, complete with saving and restoring your session). It started to make even less sense for Struts to half-implement a feature that containers are implementing fully. A more minor point is that freezing the configuration information at application startup time allows Struts to safely access the mapping information without bothering with synchronization. The "startup-only" strategy creates a modest but real improvement in performance for all users. So, ReloadAction is not supported since Struts 1.1 for two reasons: 1.It never did let you reload everything that you would really want to -- particularly changed classes -- so many people ended up having to reload the webapp anyway. 2.Containers are starting to offer reload-on-demand features which does the same thing as the Struts ReloadAction, only better. 3.Not supporting ReloadAction lets Struts avoid doing synchronization locks around all the lookups (like figuring out which action to use, or the destination of an ActionForward) so applications can run a little faster. Of course, if someone came up with an implementation that solved these problems without creating any others, we would not be opposed to including a new ReloadAction. Q.What is a modular application? What does module-relative mean? A.Since Struts 1.1, the framework supports multiple application modules. All applications have at least one root, or default, module. Like the root directory in a file system, the default application has no name. (Or is named with an empty string, depending your viewpoint.) Developing an application with only a default module is no different from how applications were developed under Struts 1.0. Since Struts 1.1, you can add additional modules to your application, each of which can have their own configuration files, messages resources, and so forth. Each module is developed in the same way as the default module. Applications that were developed as a single module can added to a multiple module application, and modules can promoted to a standalone application without change. For more about configuring your application to support multiple modules, see Configuring Applications in the User Guide. But to answer the question =:0), a modular application is a Struts application that uses more than one module. Module-relative means that the URI starts at the module level, rather than at the context level, or the absolute-URL level. 1.Absolute URL: http://localhost/myApplication/myModule/myAction.do 2.context-relative: /myModule/myAction.do 3.module-relative: /myAction.do The Struts Examples application is a modular application that was assembled from several applications that were created independently. Q.Why are some of the class and element names counter-intuitive? A.The framework grew in the telling and, as it evolved, some of the names drifted. The good thing about a nightly build, is that everything becomes available to the community as soon as it is written. The bad thing about a nightly build is that things like class names get locked down early and then become difficult to change. Q.Why is ActionForm a base class rather than an interface? A.The MVC design pattern is very simple to understand but much more difficult to live with. You just need this little bit of Business Logic in the View logic or you need just that little bit of View logic in the Business tier and pretty soon you have a real mess.Making ActionForm a class takes advantage of the single inheritance restriction of Java to it makes it more difficult for people to do things that they should not do.ActionForms implemented as interfaces encourage making the property types match the underlying business tier instead of Strings, which violates one of the primary purposes for ActionForms in the first place (the ability to reproduce invalid input, which is a fundamental user expectation). ActionForms as an interface would also encourage using existing DAO objects as ActionForms by adding ‘implements ActionForm to the class. This violates the MVC design pattern goal of separation of the view and business logic. Since the goal of struts is to enforce this separation, it just makes more sense for Struts to own the ActionForm. DynaActionForms relieve developers of maintaining simple ActionForms. For near zero maintenance, try Niall Pemberton's LazyActionForm Q.Do ActionForms have to be true JavaBeans? A.The utilities that Struts uses (Commons-BeanUtils since 1.1) require that ActionForm properties follow the JavaBean patterns for mutators and accessors (get*,set*,is*). Since Struts uses the Introspection API with the ActionForms, some containers may require that all the JavaBean patterns be followed, including declaring "implements Serializable" for each subclass. The safest thing is to review the JavaBean specification and follow all the prescribed patterns. Since Struts 1.1, you can also use DynaActionForms and mapped-backed forms, which are not true JavaBeans. For more see ActionForm classes in the User Guide and Using Hashmaps with ActionForms in this FAQ. Q.Can I use multiple HTML form elements with the same name? A.Yes. Define the element as an array and Struts will autopopulate it like any other. private String[] id= {}; public String[] getId() { return this.id; } public void setItem(String id[]) {this.id = id;} And so forth Q.Can I use multiple HTML form elements with the same name? A.Yes. The issue is that only one action class can be associated with a single form. So the real issue is how do I decode multiple submit types to a single Action class. There is more than one way to achieve this functionality.The way that is suggested by struts is right out of the javadoc for LookupDispatchAction . Basically, LookupDispatchAction is using the keys from ApplicationProperties.resources as keys to a map of actions available to your Action class. It uses reflection to decode the request and invoke the proper action. It also takes advantage of the struts tags and is straight forward to implement. You can roll your own with JavaScript events and javascript:void (document.forms["myform"].submit) on any html element. This gives you control of how you want your page to look. Again you will have to decode the expected action in the execute method of your action form if you choose this route. Q.Why doesn't the focus feature on the tag work in every circumstance? A.Unfortunately, there is some disagreement between the various browsers, and different versions of the same browser, as to how the focus can be set. The tag provides a quick and easy JavaScript that will set the focus on a form for most versions of most browsers. If this feature doesn't work for you, then you should set the focus using your own JavaScript. The focus feature is a convenient "value-add" -- not a core requirement of the tag. If you do come up with a JavaScript that provides the final solution to this project, please post your patch to this Bugzilla ticket. Q.Why are my checkboxes not being set from ON to OFF? A.A problem with a checkbox is that the browser will only include it in the request when it is checked. If it is not checked, the HTML specification suggests that it not be sent (i.e. omitted from the request). If the value of the checkbox is being persisted, either in a session bean or in the model, a checked box can never unchecked by a HTML form because the form can never send a signal to uncheck the box. The application must somehow ascertain that since the element was not sent that the corresponding value is unchecked.The recommended approach for Struts applications is to use the reset method in the ActionForm to set all properties represented by checkboxes to null or false. The checked boxes submitted by the form will then set those properties to true. The omitted properties will remain false. Another solution is to use radio buttons instead, which always submit a value. It is important to note that the HTML specification recommends this same behavior whenever a control is not "successful". Any blank element in a HTML form is not guaranteed to submitted. It is therefor very important to set the default values for an ActionForm correctly, and to implement the reset method when the ActionForm might kept in session scope. Q.Can't I just create some of my JavaBeans in the JSP using a scriptlet? A.Struts is designed to encourage a Model 2/MVC architecture. But there is nothing that prevents you from using Model 1 techniques in your JavaServer Pages, so the answer to the question is "Yes, you can". Though, using Model 1 techniques in a Struts application does go against the grain. The approach recommended by most Struts developers is to create and populate whatever objects the view may need in the Action, and then forward these through the request. Some objects may also be created and stored in the session or context, depending on how they are used. Likewise, there is nothing to prevent you from using scriptlets along with JSP tags in your pages. Though, many Struts developers report writing very complex scriplet-free applications and recommend the JSP tag approach to others. For help with Model 1 techniques and scriptlets, you might consider joining the Javasoft JSP-interest mailing list, where there are more people still using these approaches. Q.Can I use JavaScript to submit a form? A.You can submit a form with a link as below. BTW, the examples below assume you are in an block and 'myForm' is picked up from the struts-config.xml name field of the action. My Link Now the trick in the action is to decode what action you intend to perform. Since you are using JavaScript, you could set a field value and look for it in the request or in the form. ... html/javascript part ... onclick='document.forms["myForm"].myAction.value="save"; document.forms["myForm"].submit();' /> onclick='document.forms["myForm"].myAction.value="delete"; document.forms["myForm"].submit();' /> ... the java part ... class MyAction extends ActionForm implements Serializable { public ActionForward execute (ActionMapping map, ActionForm form, HttpServletRequest req, HttpServletResponse) { String myAction = req.getParameter("myAction"); if (myAction.equals("save") { // ... save action ... } else if (myAction.equals("delete") { // ... delete action ... } } } } This is just one of many ways to achieve submitting a form and decoding the intended action. Once you get used to the framework you will find other ways that make more sense for your coding style and requirements. Just remember this example is completely non-functional without JavaScript. Q.How do I use JavaScript A.Struts is mainly a server-side technology. We bundled in some JSP tags to expose the framework components to your presentation page, but past that, the usual development process applies. Interactive pages require the use of JavaScript. If you want things popping up or doing this when they click that, you are outside the scope of Struts and back into the web development mainstream. You use JavaScript with Struts the same way you use with any presentation page. Since JavaScript is a client-side technology, you can use simple relative references to your scripts. If you need to fire a JavaScript from a HTML control, the Struts HTML tags have properties for the JavaScript events.You need to set checkbox properties to false if the ActionForm is being retained in session scope. This is because an unchecked box does not submit an attribute. Only checked boxes submit attributes. If the form is in session scope, and the checkbox was checked, there is no way to turn it back off without the reset method. Resetting the properties for other controls, or for a request scope form, is pointless. If the form is in request scope, everything already just started at the initial value. Q.How can I scroll through list of pages like the search results in google? A.Many Struts developers use the Pager from the JSPTags site. http://jsptags.com/tags/navigation/pager/ Q.Why do the Struts tags provide for so little formatting? A.The Struts tags seem to provide only the most rudimentary functionality. Why is there not better support for date formatting and advanced string handling? Three reasons: 1.Work started on the JSTL and we didn't want to duplicate the effort. 2.Work started on Java Server Faces, and we didn't want to duplicate that effort either. 3.In a Model 2 application, most of the formatting can be handled in the ActionForms (or in the business tier), so all the tag has to do is spit out a string. This leads to better reuse since the same "how to format" code does not need to be repeated in every instance. You can "say it once" in a JavaBean and be done with it. Since the Struts tags are open source, you can extend them to provide whatever additional formatting you may need. If you are interested in a pre-written taglib that offers more layout options, see the struts-layout taglib.In the same arena, there is a well regarded contributor taglib that can help you create Menus for your Struts applications. Q.Why does the tag URL-encode javascript and mailto links? A.The tag is not intended for use with client-side references like those used to launch Javascripts or email clients. The purpose of link tag is to interject the context (or module) path into the URI so that your server-side links are not dependent on your context (or module) name. It also encodes the link, as needed, to maintain the client's session on the server. Neither feature applies to client-side links, so there is no reason to use the tag. Simply markup the client-side links using the standard tag. Q.Why does the option tag render selected=selected instead of just selected? A.Attribute minimization (that is, specifying an attribute with no value) is a place where HTML violates standard XML syntax rules. This matters a lot for people writing to browsers that support XHTML, where doing so makes the page invalid. It's much better for Struts to use the expanded syntax, which works the same on existing browsers interpreting HTML, and newer browsers that expect XHTML-compliant syntax. Struts is following the behavior recommended by the XHTML specification Q.Do I have to use JSPs with my application? A.The short answer to this question is: No, you are not limited to JavaServer Pages. The longer answer is that you can use any type of presentation technology which can be returned by a web server or Java container. The list includes but is not limited to: 1.JavaServer Pages, 2.HTML pages, 3.WML files, 4.Java servlets, 5.Velocity templates, and 6.XML/XLST Some people even mix and match apparently unrelated technologies, like PHP, into the same web application. Q.Do ActionForms have to be true JavaBeans? A.ActionForms are added to a servlet scope (session or request) as beans. What this means is that, for certain functionality to be available, your ActionForms will have to follow a few simple rules. First, your ActionForm bean must have a zero-arguments constructor. This is required because Struts must be able to dynamically create new instances of your form bean class, while knowing only the class name. This is not an onerous restriction, however, because Struts will also populate your form bean's properties (from the request parameters) for you. Second, the fields of your form bean are made available to the framework by supplying public getter and setter methods that follow the naming design patterns described in the JavaBeans Specification. For most users, that means using the following idiom for each of your form bean's properties: private {type} fieldName; public {type} getFieldName() { return (this.fieldName); } public void setFieldName({type} fieldName) { this.fieldName = fieldName; } Q.Do I have to have a separate ActionForm bean for every HTML form? A.This is an interesting question. As a newbie, it is a good practice to create a new ActionForm for each action sequence. You can use DynaActionForms to help reduce the effort required, or use the code generation facilities of your IDE.Some issues to keep in mind regarding reuse of form beans are as follows: 1.Validation - You might need to use different validation rules depending upon the action that is currently being executed. 2. Persistence - Be careful that a form populated in one action is not unexpectedly reused in a different action. Multiple entries in struts-config.xml for the same ActionForm subclass can help (especially if you store your form beans in session scope). Alternatively, storing form beans in request scope can avoid unexpected interactions (as well as reduce the memory footprint of your application, because no server-side objects will need to be saved in between requests. 3.Checkboxes - If you do as recommended and reset your boolean properties (for fields presented as checkboxes), and the page you are currently displaying does not have a checkbox for every boolean property on the form bean, the undisplayed boolean properties will always appear to have a false value. 4.Workflow - The most common need for form bean reuse is workflow. Out of the box, Struts has limited support for workflow, but a common pattern is to use a single form bean with all of the properties for all of the pages of a workflow. You will need a good understanding of the environment (ActionForms, Actions, etc.) prior to being able to put together a smooth workflow environment using a single form bean. As you get more comfortable, there are a few shortcuts you can take in order to reuse your ActionForm beans. Most of these shortcuts depend on how you have chosen to implement your Action / ActionForm combinations. Q.How can I prepopulate a form? A.The simplest way to prepopulate a form is to have an Action whose sole purpose is to populate an ActionForm and forward to the servlet or JSP to render that form back to the client. A separate Action would then be use to process the submitted form fields, by declaring an instance of the same form bean name. The struts-example example application that is shipped with Struts illustrates this design pattern nicely. Note the following definitions from the struts-config.xml file: ... ... type="org.apache.struts.webapp.example.RegistrationForm"/> ... ... ... type="org.apache.struts.webapp.example.EditRegistrationAction" name="registrationForm" scope="request" validate="false"/> ... type="org.apache.struts.webapp.example.SaveRegistrationAction" name="registrationForm" input="registration" scope="request"/>
|
Monday, January 31, 2011
Struts Interview Questions - Part1
Labels:
Struts Interview Questions
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment