• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Struts Interview Questions Answers

Question - 11 : - What is a modular application? What does module-relative mean?

Answer - 11 : - 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. * Absolute URL: http://localhost/myApplication/myModule/myAction.do * context-relative: /myModule/myAction.do * module-relative: /myAction.do The Struts Examples application is a modular application that was assembled from several applications that were created independently.

Question - 12 : - Both JSF and Struts will continue to exist for a while. The Struts community is aware of JSF and is positioning itself to have strong support for JSF. See What about JSTL and JavaServer faces?

Answer - 12 : - From a tools perspective, if you look at the support for JSF versus Struts in WebSphere Studio, the Struts tools are focused around the controller aspects. The Web Diagram editor helps build your Struts configuration and the wizards/editors build Struts artifacts. The JSF tools are geared towards building pages, and in essence, hide the JSF framework from you. Expect WebSphere Studio to support both frameworks for a while. As JSF matures, expect to see some of the controller aspects in JSF to become toolable.

Question - 13 : - Why it called Struts?

Answer - 13 : - 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.

Question - 14 : - Who makes the Struts?

Answer - 14 : - Struts is hosted by the Apache Software Foundation(ASF) as part of its Jakarta project, like Tomcat, Ant and Velocity.

Question - 15 : - How Struts control data flow?

Answer - 15 : - Struts implements the MVC/Layers pattern through the use of ActionForwards and ActionMappings to keep control-flow decisions out of presentation layer.

Question - 16 : - When is the best time to validate input?

Answer - 16 : - This is an excellent question. Let's step back a second and think about a typical mid to large size application. If we start from the back end and work toward the view we have: 1) Database: Most modern databases are going to validate for required fields, duplicate records, security constraints, etc. 2) Business Logic: Here you are going to check for valid data relationships and things that make sense for the particular problem you are triing to solve. ... This is where struts comes into the picture, by now the system should be pretty well bulletproof. What we are going to do is make validation friendlier and informative. Rember it is OK to have duplicate validations... 3) ActionErrors validate(ActionMapping map, HttpServletRequest req) is where you can do your validation and feed back to the view, information required to correct any errors. validate is run after the form has been reset and after the ActionForm properties have been set from corresponding view based input. Also remember you can turn validation off with validate="false" in the action mapping in the struts-config.xml. This is done by returning an ActionErrors collection with messages from your ApplicationResources.properties file. Here you have access to the request so you can see what kinds of action is being requested to fine tune your validations. The <html:error> tag allows you to dump all errors on your page or a particular error associated with a particular property. The input attribute of the struts-config.xml action allows you to send validation errors to a particular jsp / html / tile page. 4) You can have the system perform low level validations and client side feedback using a ValidatorForm or its derivatives. This will generate javascript and give instant feedback to the user for simple data entry errors. You code your validations in the validator-rules.xml file. A working knowledge of regular expressions is necessary to use this feature effectively.

Question - 17 : - What about JSTL and JavaServer Faces ?

Answer - 17 : - 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.

Question - 18 : - When do I need "struts.jar" on my classpath?

Answer - 18 : - 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. Why is that an important distinction? 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: * 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). * Use an IDE where you can configure the "class path" used for compilation independent of the CLASSPATH environment variable. * Use a shell script that temporarily adds struts.jar to the classpath just for compilation, for example javac -classpath /path/to/struts.jar:$CLASSPATH $@

Question - 19 : - Why do the Struts tags provide for so little formatting?

Answer - 19 : - 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: First, work started on the JSTL and we didn't want to duplicate the effort. Second, work started on Java Server Faces, and we didn't want to duplicate that effort either. Third, 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. Why don't the Struts taglibs offer more layout options? 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.

Question - 20 : - Can I have an Action without a form?

Answer - 20 : - Yes. If your Action does not need any data and it does not need to make any data available to the view or controller component that it forwards to, it doesn't need a form. A good example of an Action with no ActionForm is the LogoffAction in the struts example application: <action path="/logoff" type="org.apache.struts.webapp.example.LogoffAction"> <forward name="success" path="/index.jsp"/> </action> This action needs no data other than the user's session, which it can get from the Request, and it doesn't need to prepare any view elements for display, so it does not need a form. However, you cannot use the <html:form> tag without an ActionForm. Even if you want to use the <html:form> tag with a simple Action that does not require input, the tag will expect you to use some type of ActionForm, even if it is an empty subclass without any properties.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners