Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Struts Interview Questions and Answers

Ques 51. Why do the Struts tags provide for so little formatting?

Ans. 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.

Is it helpful? Add Comment View Comments
Ques 52. Why does the <html:link> tag URL-encode javascript and mailto links?
Ans. The <html:link> 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 <html:link> tag. Simply markup the client-side links using the standard tag.
Is it helpful? Add Comment View Comments
Ques 53. Why does the option tag render selected=selected instead of just selected?
Ans. 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.

<select id="item" name="item" selected="selected">
<option value="option1">Option1</option>
<option value="option2">Option2</option>
Is it helpful? Add Comment View Comments
Ques 54. Do I have to use JSPs with my application?
Ans. 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:
* JavaServer Pages,
* HTML pages,
* WML files,
* Java servlets,
* Velocity templates, and
Some people even mix and match apparently unrelated technologies, like PHP, into the same web application.
Is it helpful? Add Comment View Comments
Ques 55. Do I have to have a separate ActionForm bean for every HTML form?
Ans. 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:
* Validation - You might need to use different validation rules depending upon the action that is currently being executed.
* 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.
* 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.
* 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.

How can I prepopulate a form?
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:

<-- Registration form bean -->


<-- Edit user registration -->
<-- Save user registration -->

Note the following features of this approach:
* Both the /editRegistration and /saveRegistration actions use the same form bean.
* When the /editRegistration action is entered, Struts will have pre-created an empty form bean instance, and passed it to the execute() method. The setup action is free to preconfigure the values that will be displayed when the form is rendered, simply by setting the corresponding form bean properties.
* When the setup action completes configuring the properties of the form bean, it should return an ActionForm that points at the page which will display this form. If you are using the Struts JSP tag library, the action attribute on your tag will be set to /saveRegistration in order for the form to be submitted to the processing action.
* Note that the setup action (/editRegistration) turns off validation on the form that is being set up. You will normally want to include this attribute in the configuration of your setup actions, because you are not planning to actually process the results -- you simply want to take advantage of the fact that Struts will precreate a form bean instance of the correct class for you.
* The processing action (/saveRegistration), on the other hand, leaves out the validate attribute, which defaults to true. This tells Struts to perform the validations associated with this form bean before invoking the processing action at all. If any validation errors have occurred, Struts will forward back to your input page (technically, it forwards back to an ActionForward named "registration" in this case, because the example webapp uses the inputForward attribute in the element -- see the documentation describing struts-config.xml for more information) instead of calling your processing action.
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2016 WithoutBook