Search

Complete reference to struts frame work interview questions basic to advanced level : SE to Team Lead level Part - 8

DynaBean and BeanUtils
Another major complaint usually heard amongst Struts 1.0 users is the extensive effort involved in writing the FormBean (a.k.a. ActionForm) classes.
Struts provides two-way automatic population between HTML forms and Java objects, the FormBeans. To take advantage of this however, you have to write one FormBean per HTML form. (In some use cases, a FormBean can actually be shared between multiple HTML forms. But those are specific cases.) Struts' FormBean standard follows faithfully the verbose JavaBean standard to define and access properties. Besides, to encourage a maintainable architecture, Struts enforces a pattern such that it is very difficult to 'reuse' a model-layer object (e.g. a ValueObject from the EJB tier) as a FormBean. Combining all these factors, a developer has to spend a significant amount of time to write tedious getters/setters for all the FormBean classes.
Struts 1.1 offers an alternative, Dynamic ActionForms, which are based on DynaBeans. Simply put, DynaBeans are type-safe name-value pairs (think HashMaps) but behave like normal JavaBeans with the help of the BeanUtils library. (Both the DynaBeans and the BeanUtils library were found to be useful and generic enough that they have been 'promoted' into Jakarta's Commons project.) With Dynamic ActionForms, instead of coding the tedious setters/getters, developers can declare the required properties in the struts-config.xml files. Struts will instantiate and initialize Dynamic ActionForm objects with the appropriate metadata. From then onwards, The Dynamic ActionForm instance is treated as if it is an ordinary JavaBean by Struts and the BeanUtils library. 
Validator
The Validator is not exactly a new feature. The Validator has been in the contrib package in the distribution since Struts 1.0.1. Since then, part of it has now been refactored and moved into the Jakarta-Commons subproject and renamed the Commons-Validator and the Struts specific portion is now called the Struts-Validator. However, since it is in the contrib package, people may overlook it and it is worthwhile to mention it here.
The Validator provides an extensible framework to define validation rules to validate user inputs in forms. What is appealing in the Validator is that it generates both the server-side validation code and the client-side validation code (i.e. Javascript) from the same set of validation rules defined in an XML configuration file. The Validator performs the validation based on regular-expression pattern matching. While a handful of commonly used validators are shipped with the framework (e.g. date validator, range validator), you can always define your own ones to suit your need.


Default Sub-application
To maintain backward compatibility, Struts 1.1 allows one default sub-application per application. The URI of the resources (i.e. JSPs, HTMLs, etc) in the default sub-application will have an empty sub-app prefix. This means when an existing 1.0 application is "dropped" into Struts 1.1, theoretically, it will automatically become the default sub-application.


Direct Requests to JSPs
To take the full advantage of sub-application support, Struts 1.1 stipulates the requirement that all requests must flow through the controller servlet, i.e. the ActionServlet. Effectively, this means all JSPs must be fronted by Actions. Instead of allowing direct requests to any of the JSPs, all requests must go through an Action and let the Action forward to the appropriate JSP.
This is perhaps the biggest impact of migration to Struts 1.1 if you have not followed this idiom in your applications. This restriction is required because without going through the ActionServlet, Struts navigation taglibs (e.g. <html:form> and <html:link>) used in the JSPs will not have the correct sub-app context to work with.
ActionServlet Configurations
With the introduction of sub-applications, a more flexible way is introduced to configure each sub-application independently. Many of the configuration entries (e.g. resource bundle location, maximum upload file size, etc) that used to be defined in web.xml have now been moved to struts-config.xml. The original entries in web.xml are deprecated but will still be effective.


Action.execute() and Action.getResources()
In Struts 1.0, request handling logic is coded in Action.perform(); however, Action.perform() throws only IOException and SevletException. To facilitate the new declarative exception handling , the request handling method needs to throw Exception, the superclass of all the checked exceptions. Therefore, to both maintain backward compatibility and facilitate declarative exception handling, Action.perform() is now deprecated in favour of Action.execute().
You also have to be careful if you use DispatchAction in your existing applications. At the time of writing, the DispatchAction in Struts 1.1 beta has not yet been updated to use execute(). (A bug report has been filed in Struts' bug database.) Therefore, without modifying the DispatchAction class yourself, declarative exception handling will not work with DispatchAction subclasses.
In addition, Action.getResources() is now deprecated. Instead, you should call Action.getResources(HttpServletRequest) instead. This allows Struts to return to you the sub-application specific message resources. Otherwise, the message resources for the default sub-app will be used.


Library Dependency
Struts 1.1 now depends on a handful of libraries from other Jakarta subprojects (e.g. Commons-Logging, Commons-Collections, etc.). Some of these libraries may cause classloading conflicts in some servlet containers. So far, people have reported in the mailing list the classloading problem of commons-digester/jaxp1.1, and commons-logging causing deployment difficulties in Struts 1.1 applications running on Weblogic 6.0. (The problems have been corrected in Weblogic 6.1 and 7.0.)


Resources under WEB-INF
According to the Servlet specification, resources (e.g. JSP files) stored under WEB-INF are protected and cannot be accessed directly by the browsers. One design idiom for Struts 1.0 is to put all the JSP files under WEB-INF and front them by Actions so that clients cannot illegally access the JSPs. With the introduction of sub-application prefixes in Struts 1.1, mapping resources under WEB-INF gets complicated. Extra configuration steps utilizing the pagePattern and forwardPattern attributes of the element in struts-config.xml is required to inform Struts to construct the paths correctly. More specifically, you need to set these attributes to the pattern "/WEB-INF/$A$P".
What is the Jakarta Struts Framework?
Jakarta Struts is an open source implementation of MVC
(Model-View-Controller) pattern for the development of web based applications.
Jakarta Struts is a robust architecture and can be used for the development of applications of any size.
The “Struts framework” makes it easier to design scalable, reliable Web applications.
What is an ActionServlet?
The class org.apache.struts.action.ActionServlet is called the ActionServlet.
In the Jakarta Struts Framework this class plays the role of controller.
All the requests to the server go through the “Controller”.
The “Controller” is responsible for handling all the requests.
How can one make any “Message Resources” definitions file available to the “Struts Framework” environment?
Answer: “Message Resources” definitions file are simple .properties files and
these files contain the messages that can be used in the struts project.
“Message Resources” definition files can be added to the struts-config.xml file
through <message-resources /> tag. Example:
<message-resources parameter="MessageResources" />
What is an “Action Class”?
The “Action Class” is part of the “Model” and is a wrapper around the business logic.

The purpose of the “Action Class” is to translate the HttpServletRequest to the business logic.

To use the “Action”, we need to subclass and overwrite the execute() method.

All the database and business processing is done in the “Action” class.

It is advisable to perform all the database related work in the “Action” class.

The ActionServlet (command) passes the parameterized class to ActionForm using the execute() method.

The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file according to the value of the returned ActionForward object.
Write code of any Action Class?
Here is the code of Action Class that returns the ActionForward object.

package j2eeonline.jdj.com;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class TestAction extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception{
return mapping.findForward("testAction");
}
}
What is an “ActionForm”?
An “ActionForm” is a JavaBean that extends org.apache.struts.action.ActionForm.
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.  
What is Struts Validator Framework?
The “Struts Framework” provides the functionality to validate the form data.
It can be used to validate the data in the user’s browser as well as on the server side.
Struts Framework checks the JavaScript code and it can be used to validate the form data on the client browser.

Server side validation of form data can be accomplished by subclassing your “form” Bean with DynaValidatorForm class.

The “Validator” framework was developed by David Winterfeldt as a third-party “add-on” to Struts.
Now the Validator framework is part of the “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 any making any additional settings.
Describe the details of XML files used in the “Validator Framework”?
The Validator Framework uses two XML configuration files

1) validator-rules.xml and

2) 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 would you display “validation fail” errors on a JSP page?
Following tag displays all the errors:
 <html:errors/>
How can one enable front-end validation based on the xml in validation.xml?
The
<html:javascript>
 tag allows front-end validation based on the xml in validation.xml.

For example the code:

generates the client side JavaScript for the form "logonForm" as defined in the validation.xml file.
The <html:javascript> when added in the JSP file generates the client side validation script.

class A extends ActionSupport{ }class B extends A{}Is B also acts as an action class or not? Explain 
Latest Answer: Yes if all the methods of the action class defined in Class B then it is sure act as a Action class. ...
Read Answers (1) | Asked by : sekhark

Latest Answer: Forward ActionInclude actionDispatch ActionLookup Dispatch Action ...
Read Answers (2) | Asked by : har_5047

What are the advantages and disadvantages of Struts 2 Framework? 
Latest Answer: 1. no need coding action forms2. can be any method3. action name can contain place holders4. interceptors5. value stacks6. thread safecompared to struts 1 ...
Read Answers (2) | Asked by : snjy85

Why we use Struts framework in project? 
Latest Answer: Struts Framework provides layered architecture which decouples the Model, View and Controller. Hence we can seperate businees logic from presentation logic.  Maintenance is easy. This is achieved by MVC 2 architecture. Here Only one controller ...

What is heirarchy of files in Struts?  
Latest Answer: When the request is recived by ActionServlet it looks for the ActionMapping entries in the Struts-config.xml. ActionMapping returns the appropriate Action class where we handle the business logic.Finally execute() returns the ActionForward key (View). ...

Latest Answer: We can configure the database connection by setting the connectino atributes in server.xml file which is available in conf folder in the tomcat home path. In this server.xml file there is an tag attributes related make connection pool for any database. ...
Read Answers (4) | Asked by : naggeek

iam not able to disable a JSP in Mozilla but its working fine in IE7 can any one guide me sending the code line for this  
Latest Answer: get the header of mozila and apply condition for this perticular condition u can ban the page to display on mozilla ...

why do we have only one ActionServlet in Struts?(Asked in Polaris Interview for Java Experienced people , on April 11, Chennai) 
Latest Answer: This is so because struts implements MVC and in an MVC we generally (almost 99%) have only one controller. The ActionServlet acts as a controller. ...

What is the difference between Struts 1.x and Struts 2.x 
Latest Answer: Feature Struts 1 Struts 2 Action classes Struts1 extends the abstract base class by its action class. The problem with struts1 is that it uses the abstract classes rather than interfaces. While in Struts 2, an Action class implements an Action interface, ...
Read Answers (1) | Asked by : siva2baba

What are the helper file in the form of JSPs available in struts?.Is struts tags are XHTML supportive? 
View Question | Asked by : gotlururaja

Help me 
Latest Answer: The only difference between the two isexecute() throws Expection whereasperform() throws IOException and ServletExceptionperform() has now been depricated so one should use execute() only. ...
Read Answers (3) | Asked by : Anupama

Latest Answer: Frame work automatically generate ActionServlet which is reduce the work of programmer. In traditional Servlet/JSP project programmer explicitly write Actionservlet ...
Read Answers (3) | Asked by : kiranmaye

Latest Answer: Nothing will happen at that instant. In the action, if we try to cast the action form and using it, then it will throw nullpointer exception.Regards,Mahes. ...

Action Class is Thread safe if i declare method for database connections before the execute method and when you try to access what will happen for application
Read Answers (1) | Asked by : Sreekanth Konda

Latest Answer: saveToken() method is used for duplicate form submission.Let's take an example i.e. yahoo email registration formYou filled the form and press the "submit" button more than once.For each action you do there is a request object associted with that.So when ...
Read Answers (1) | Asked by : selva

What is integration logic? How does struts frame work develop integration logic automatically using deployment descriptor?
View Question | Asked by : venky_mca

Latest Answer: If our Form has single function we have to go for action class but if our Form has to perform multiple functions then we have go for dispatch action.In struts config we have to provide parameter="methodToCall"  and in the jsp we have to   ...
Read Answers (6) | Asked by : Gangadhar P

Latest Answer: It would be misleading to say that only one instance of Servlet is created per web application. One instance of each Servlet class defined in your code is created per web application. i.e., If your application has 100 ActionServlet classes, you will have ...
Read Answers (2) | Asked by : katipelly

How do you identify user session has been ended (at a particular time ) and forward a page to login page automatically
Read Answers (4) | Asked by : vijayganesh mech

Latest Answer: Struts does not bind the programmer till the DAO layer. You can have anything you like, as the return type (valid in programming construts, of course) for the DAO method, Struts would not crib about anything, and would be happy to serve your Action class, ...
Read Answers (3) | Asked by : sanjib

Latest Answer: Actually the confusion is between two classes Action and ActionServlet. Be clear that these two are different classes. ActionServlet is a servlet but Action is a normal java class. ...
Read Answers (11) | Asked by : enjoy

Latest Answer: A Forward Action is a standard Action forwards the request to the context-relative URI(JSP/Servlet) specified by the parameter property of the associated ActionMapping.To configure the use of the Forward Action in your struts-config.xml file, create ...
Read Answers (2) | Asked by : kiran.p

Latest Answer: Struts tags bind the property value with the Formbean property defined. ...
Read Answers (4) | Asked by : raghava_

Latest Answer: 1. HTML tags are static Struts tags are Dynamic (At the run-time struts tags are called) 2. Another diff is You create your own Struts tags... ...
Read Answers (1) | Asked by : Struts

What are the contents of web.xml and struts-config.xml? What is the difference between them? How to relate these tow xml files?
Read Answers (7) | Asked by : Akila

In struts servlet control the application and we know that a jsp compiled into a servlet first. The only problem with the servlet is that it needs to write out.println call per HTML line. But as a controller 
Latest Answer: Satisfied with the above comment. Why we are using struts, we can use JSP. as we know the advantages of Struts, so we use it. So we use Servlet that is for writing logic, as a controller. JSP is for Presentation. ...
Read Answers (2) | Asked by : khalid_it

Latest Answer: We can have more than one Action Servlet but Struts controller follows the front controller design pattern. As per this pattern we will have only one controller. Designing more than one action servlet is breaking the rule of design pattern. ...
Read Answers (5) | Asked by : swetha

Latest Answer: REquest diapatcher servlet which filters the action servlet actions is added in 1.2 ...
Read Answers (2) | Asked by : Srinivas

Should every html form property have a corresponding formbean get/set and variable.?Can form property be omitted in a form bean?
Read Answers (5) | Asked by : shobana24

Can input form property be omitted in a formbean ? is it mandatory for every form property to have a corresponding formbean get/set and variable ?
Read Answers (4) | Asked by : Shobana

If any one knows the answer plz add.. 
Latest Answer: in order to access the resources 
Read Answers (4) | Asked by : Rafi

Latest Answer: Hi,Struts Extras provides several popular but non-essential classes, including: ActionDispatcher An Action helper class that dispatches to a public method in an Action.  BaseAction BaseAction is provided as an intermediate class for shared funtionality ...
Read Answers (2) | Asked by : Sujatha

Latest Answer: Hi,If I have understood your question properly. You want  to map two forms with one action class..It can be done but its not really good idea to do by means of design if they are not from same inheritance.Form Hierachy, Like,  User -> Customer ...
Read Answers (4) | Asked by : mytramesh

Latest Answer: Use the Service Locator pattern to look up the ejbs Or you can use InitialContext and get the home interface ...
Read Answers (3) | Asked by : prasad

Latest Answer: In Struts1.0 have perform() methos in action class where as struts 1.1 have excute() method in action classAcction messages () are introduced in struts1.1DynaactionForms are introduce in struts1.1 ...

Latest Answer: Difference in output.ex: if we forward from one.jsp to two.jsp the contents of only two.jsp will be generated .     if we include two.jsp in one.jsp the contents of both the jsp's will be generated ...
Read Answers (3) | Asked by : Rajeshwar

Latest Answer: Yes, we can have more than one struts-config.xml file in a web application.Each struts-config.xml file for different modules in our application.Declaration in web.xml is:config/pullman/WEB-INF/calculator/struts-pullman-config.xml ...
Read Answers (10) | Asked by : Suresh.M

Latest Answer:    MVC is generlised architecture. There is no MVC1 and MVC2. According to Sun Microsystems in MVC Model1 driven architecture Controller and view is JSP and model is bean. In MVC model2 driven architecture we will use Servlet as controller, ...
Read Answers (5) | Asked by : bhupathi

Latest Answer: Hi,According to my knowledge,If the same condition is mapped to the same jsp page in multiple actions we use global variable i.e to avoid repititon. ...
Read Answers (1) | Asked by : Raj

Latest Answer: Container doesn't know about any thing. what ever is configured in application's web.xml it will take it as a configuration. We can configure our own MVC implmentation and front controller in application configuration (i.e. web.xml) instead of ActionServlet. ...
Read Answers (7) | Asked by : purandhar

Latest Answer: Few Disadvantage are mentioned in the below link. Struts have disadvantages mainly on performance of the application. Especially when using advanced tag like nested-loop etc, Resulting in creating many Forms object then required.http://www.coreservlets.com/Apache-Struts-Tutorial/Understanding-Struts.html ...

Please anybody send the abbreviation of struts? this is the question i have faced in the interview?
Read Answers (7) | Asked by : rajesh

Latest Answer: 1. A request comes in with a .do extension, the container maps it to the ActionServlet. 2. The ActionServlet acts like a front end controller and dispatches control to a RequestProcessor. 3. The RequestProcessor finds an action tag with a path attribute ...
Read Answers (7) | Asked by : kalpana

Latest Answer:  hiwhen ever start the web application the web container creates AcctionServlet object by using load-on-startup method. then it gets the config init parameter. then read the config-xml file.cheerssiva ...
Read Answers (3) | Asked by : Deven

Latest Answer: Differences between Struts 1.1 and 1.2  :-1) Adviced for replacement of ActionErrors with ActionMessages2) org.apache.struts.Action statics: Use org.apache.struts.Global statics instead3) Many utility methods previously found in org.apache.struts.utils.RequestUtils ...

Latest Answer: bean:message retrieves an internationalized message for the specified locale, using the specified message key, and write it to the output stream. Up to five parametric replacements (such as "{0}") may be specified.The message key may be specified ...
Read Answers (4) | Asked by : pavani

Latest Answer: Hi Folks,Ordinary Servlets:These are extends HttpServlet, and service the req, and send the response to the client. At the time, servicing, the container will create the objects for this servlets, when ever, it needs.ActionServlet:This also extends HttpServlet. ...

Latest Answer: in struts 2.o we have a new cancel functionality by which on pressing cancel we can go to a differen action. ...
Read Answers (2) | Asked by : Sridevi

Latest Answer: the exadel studio is one of the plug-in for struts ...
Read Answers (3) | Asked by : Satheesh Jayabalan


Latest Answer: in struts 1.0 we have to override perform method from 1.1 onwords execute method was introduced.this supports us to throw any exception,i.e,thia provides declarative exception handling. ...

ActionForm class is used to capture user-input data from an HTML form and transfer it to the Action Class. ActionForm plays the role of Transport Vehicle between the presentation Tire & Business Tier.Life 
Latest Answer: An ActionForm is a java bean that extends org.apache.struts.action.ActionForm, ActionForm maintain the session state of web application.All data submitted by the user are sent corresponding ActionForm  ...
Read Answers (1) | Asked by : Kamal Lochan Patra, UBIQUE

LookupDispatchAction is like DispatchAction but LookupDispatchAction uses the value of the request parameter to perform a reverse lookup (using protected Map getKeyMethodMap() ) from the resource bundle 
Latest Answer: LookupDispatchAction is subclass of DispatchAction which actually lookup the action class method name using the request parameter value in the reverse process by looking the value in the resource bundle.i.e using map method :save.checkorder=button.checkorderin ...
Read Answers (1) | Asked by : Kamal Lochan

In struts how can i validate the values filled into the text boxes or else using DynaValidatorForm,without using javascript.Actually with javascript it is working perfect but not without javascript, and i want without javascript?
Read Answers (6) | Asked by : Raghvendra Dwivedi

Latest Answer: jsp1.Struts framework is basically using the taglib so we can import taglib, it is possible for jsp elements.Directive tag

Latest Answer: Offcourse you can make changes to actionservlet by extending it and override the particular method or funcationality which is not meeting your problem requirements.Check with RequestProcess interface and see by having you own request process class implementation ...

In struts, if any changes are made to before the request reaches to actionservlet, where you do the changes?

Latest Answer: JSPs are more towards the J2EE line. In a large jsp applications, lot of java script , css(cascaded sytle sheet) , lot of more thing are applied, with the actual information. Information is required but the presentation of information is also important. ...

Latest Answer: IN addition to whatever said in comment one, in Jakarta Struts request processor has most of the following responsibilities: 1. Determine path, 2. Handle Locale, 3. Process content and encoding type, 4.Process cache headers 5. Pre Processing hook 6.Pre-processing ...

Latest Answer: Since the very purpose of having a controller in the struts framework is to redirect the request to the appropriate action class to process the correspnding business logic, and servlet is the gateway to the web-container for each http request. ...

Latest Answer: hithe action mapping object to give the proper action to that partcular request and takes care of validation also. ...
Read Answers (2) | Asked by : K.Harikumar Reddy

Latest Answer: As the ActionMessages represent the error scenarios for the current request, they must be stored in request scope not in session scope. hence no way of thinking of removing action messages from session scope.Mahes ...
Read Answers (3) | Asked by : prasad

What is the correct syntax for removing ActionMessages from the session context? Choice 1 Action.removeErrors(); Choice 2 ActionMessages msg1 = new ActionMessages("clear"); Action.saveErrors(session, msg1); Choice 3 Action.saveErrors(session, null); Choice 4 Action.clearErrors(session, null); Choice 5 request.getSession().saveErrors(session, null);
Read Answers (1) | Asked by : N

Question: Assuming the class LoginForm contains a String property named "password", how does the LoginAction class access the attribute called "password" in the above request? Explain why.Choice 1 String password = request.getParameter("password"); Choice 2 String password = request.getAttribute("password"); Choice 3 request.getParameterNames().getParameter("password"); Choice 4 String password = ((LoginForm)
Read Answers (6) | Asked by : N

Why is the action class is singleton in nature? Isn't this creates a bottleneck for the requests?
Read Answers (3) | Asked by : Sharan

Latest Answer: both are same ...
Read Answers (13) | Asked by : bangaram

Latest Answer: Yes.We can make Action class, DAO class without form class. In this case, we can get the form elements by using HttpServletRequest.getParameter("elementName");Mahes ...
Read Answers (6) | Asked by : Vaibhav jethi

Latest Answer: both are same ...

Ans: No , when we go one page to other page then we using both , but no togetherotherwise browser incompatible problem arise. 
Latest Answer: Yes. We can achieve this either using JavaScript or action mapping. If you use JavaScript, we can use the 'location.href' to go one page to other page.If you use action mapping, we can use the findForward method to go one page to other page. ...

Is there any way to define a default method for every in the action mapping of Struts-Config.XML file? If yes then how? Give a piece of code demonstrating the same.
Read Answers (6) | Asked by : Soumen Trivedi

Latest Answer: in action mapping we specify action class for particular url ie path and diffrent target view ie forwards on to which request response will be forwarded. We also specify to which page control should go if there is validation error for ex input property ...
Read Answers (3) | Asked by : CHANDRA SEKHAR JONNALAGADDA

Latest Answer: Object is the super class for Action and ActionForm as there are no immediate super classes . ...
Read Answers (8) | Asked by : nagendra

No comments:

Post a Comment