Consultancy Services jobs Etisalat CEO ZANTEL
etisalat

Custom Search
Share/Save/Bookmark Subscribe

Struts part I

Posted by Anonymous | 3:42 PM | 0 comments »

Struts Part I

Etisalat

DEVELOPER

bangalore

india

BLOGGER

APACHE





Q.What is Struts?

Struts is a java framework based on Model 2 architecture of JSP or popularly called Model-View-Controller architecture. It provides a controller for this architecture.
Q.What is Tiles-def.xml & validation.xml in Struts?
tiles-def.xmltiles-def.xml is used as a configuration file for an appliction during tiles development You can define the layout / header / footer / body content for your View.Eg:

Content goes here


2. validation.xml
The validation.xml file is used to declare sets of validations that should be applied to Form Beans.Each Form Bean you want to validate has its own definition in this fileInside that definition, you specify the validations you want to apply to the Form Bean'sfields.
Eg:
target="_top">
form-validation
3. Resourcebundle.properties
Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails. Eg:In ApplicationResources.propertieserrors.registrationForm.name={0} Is an invalid name.
In theregistrationForm.jsp

Output(in red color) :
abc Is an invalid name ________________
1. Purpose of tiles-def.xml file is used to in the design face of the webpage. For example in the webpage "top or bottom or left is fixed" center might be dynamically chaged.It is used for the easy design of the web sites. Reusability
2. resourcebundle.properties file is used for lot of purpose. One of its purpose is internationalization. We can make our page to view on any language. It is independent of it. Just based on the browser setting it selects the language and it displayed as you mentioned in the resourcebundle.properties file.
3. Validation rule.xml is used to put all the validation of the front-end in the validationrule.xml. So it verifies. If the same rule is applied in more than one page. No need to write the code once again in each page.Use validation to chek the errors in forms.
tiles-def.xml - is required if your application incorporates the tiles framework in the "View" part of MVC. Generally we used to have a traditional JSP's (Which contgains HTML & java scriplets) are used in view.
But Tiles is an advanced (mode or less ) implementation of frames used in HTML. We used to define the frames in HTML to seperate the header html, footer html, menu or left tree and body.html to reuse the contents.
Hence in the same way, Tiles are defined to reuse the jsp's in struts like architectures, and we can define the jsp's which all are to be display at runtime, by providing the jsp names at runtime.
To incorporate this we need tile-def.xml and the Class generally which extends RequestProcessor should extend TilesRequestProcessor.resourcebundle.properties -- It is to incorporate i18n (internationalization) in View part of MVC.validation.xml - This file is responsible for business validations carried at server side before processing the request actually.
It reduces the complexity in writing _JavaScript validations, and in this way, we can hide the validations from the user, in View of MVC.
1.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. 2.Resourcebundle.properties is used to maintian all the strings that are used in the application and their corresponding equalents in different desiredlanguages. All the strings/labels in the application using Struts will get it labels from this file only depending on locale.
This is an i18n implementation of struts
3. This validation.xml configuration file defines which validation routines that is used to validate Form Beans. You can define validation logic for anynumber of Form Beans in this configuration file.
Inside that definition, you specify the validationsyou want to apply to the Form Bean's fields.
The definitions in this file use the logical names of Form Beans from the struts-config.xml file along with the logical names of validation routines from the validator-rules.xml file to tie the two together.

Q.What is DispatchAction?
DispatchAction is specialized child of Struts Action class. It combines or group the methods that can further access the bussiness logic at a single place. The method can be anyone from CRUD [Create,Retrieve,Update or Delete] or it can be security check one like authenticate user etc.
This class apart from having thread-safe execute method also can have user-defined methods.In struts-config.xml files following changes are required for Dispatch action to work:
parameter ="task" scope = "request" validate = "false"
input = "/index.jsp">


If above is your struts-config.xml file structure and LoginAction extends DispatchAction instead of normal Action class. And assuming [keep assuming] your LoginAction class have method named authenticateUser, then in your login.jsp add any hidden parameter called task with value as your method name and on submit of that page following will be the url:
Thus if we try to combine the last part of this puzzle we get the climax at struts-config.xml file's action-mapping tag described above.
The parameter property of tag have the task as it's value pointing to task variable in the request having it's value as authenticateUserhence the framework search in the LoginAction a method called authenticateUser through reflection and forwards the execution flow to it.
This is all folks, the briallancy of Struts framework. Note DispatchAction class is included in 1.1 version.
Q.How to call ejb from Struts?
We can call EJB from struts by using the service locator design pattern or by using initial context with create home object and getting return remote reference object.Q.In struts how I can 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?
Using the validate() method of the ActionForm class, the values filled in the form will be validated in the case there is no JavaScript for validating the form.

Q.What is the difference between ActionErrors and ActionMessages?
There is no difference between these two classes. All the behavior of ActionErrors was copied into ActionMessages and vice versa. 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 -- where as errors being only one kind of message.
The difference between saveErrors(...) and saveMessages(...) is simply the attribute name under which the ActionMessages object is stored, providing two convenient default locations for storing controller messages for use by the view.
If you look more closely at the html:errors and html:messages tags, you can actually use them to get an ActionMessages object from any arbitrary attribute name in any scope.

Q.What is the various Struts tag libraries?

The Struts distribution includes four tag libraries for the JSP framework (in struts-config.xml) :* Bean tag library [ struts-bean.tld ] : Contains tags for accessing JavaBeans and their properties. Developers can also define new beans and set properties* HTML tag library [ struts-html.tld ] :
Contains tags to output standard HTML, including forms, textfields, checkboxes, radio buttons* Logic tag library [ struts-logic.tld ] :
Contains tags for generating conditional output, iteration capabilities and flow management* Tiles or Template tag library [ struts-tiles.tld / struts-template.tld ] :
For tiles implementation* Nested tag library [ struts-nested.tld ] : allows the use of nested beans.
The libraries are designed to:* Facilitate the separation of presentation and business logic.* dynamically generate Web pages.
* Implement the flow of control to and from the ActionServlet.
Q.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.
Q.What are the core classes of struts?

The core classes of struts are ActionForm, Action, ActionMapping, ActionForward etc.

Q.In struts what happens if made any changes in actionservlet?

The ActionServlet plays the role of controller which is responsible for handling the request and selecting the correct Application Module and storing ApplicationConfig and MessageResource bundle in the request object. If we modify the ActionServlet the Controller may or may not work what happens that depends on your modification, You have not specify whether you want to create your own custom ActionServlet by extending ActionServlet and overriding the methods in it or what exactly you want to modify.
Q.What part of MVC does Struts represent ?

Struts is mainly famous for its Action Controller - which is nothing but the CONTROLLER part of MVC Pattern.
To add up, Struts is the framework which started mainly using the MVC-2 Pattern where in the Business logic is STRICTLY SEPARATED from the Presentation logic
Q.How you will handle errors and exceptions using Struts?

Struts exception handling can be done by two ways:
1. Declarative (using struts features via struts-config.xml) this makes coding in the Action class very simple since the execute method declares throws Exception we don't need a try-catch block. Struts saves the exception using one of its global constants.
You may use the field Globals.EXCEPTION_KEY to retrieve it from the request object.
2. Programmatic (using the usual try-catch exception handling in Action Class).


Q.What are the Important Components of Struts?

Struts Configuration File
ActionServlet
RequestProcessor
ActionForm
Action
ActionFroward
ActionMapping
ActionErrors
Q.How you will save the data across different pages for a particular client request using Struts ?

Several ways. The similar to the ways session tracking is enabled.
Using cookies, URL-rewriting, SSLSession, and possibility threw in the database.

Q.Does Struts provide support for Validator & Tiles by default ?

NO.
Struts does not provide default support for Validator and Tiles. Additional plugins are required for the purpose
Q.Is there any way to put my custom name to LIB folder which I am going to place in WEB-INF folder of struts application?

No,
not possible because web servers are strictly denoting the directory structure and names .so that it will recognize that lib is a directory having library files
Q.Can I use bc4j with spring framework no it is not possible

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

In struts the first to receive the request is Actionservlet. So, there is no chance for you to make changes before
Q.What are the drawbacks of Struts?

In struts , their is no facility of backward flow. Suppose we are in page 1 and when we submit it calls action mapping page2.
Their may be lot of variable stored in session , which is available to page2. Now we wish to go page1 from page 2, for this we have to call the action mapping of page1. But struts flow is always in forward direction.
So when we call page 1, values stored in session never get reversed. So it reduces the performance.
To resolve this problem of struts, their is a framework called Web Flow Navigation Manager(WFNM) of Sourgeforge.net.
This framework can be integrated with struts.
Q.How can we work struts on Eclipse? What is the best plug-in for this?

Eclipse work bench provides option to any web project. Building struts application becomes very easy with the GUI provided and drag drop feature of struts-config file. The best plug-in available is My-eclipse .
Q.What is the difference between a normal servlet and action servlet?
Both a normal servlet and action servlet are same, which extend HttpServlet and implement the servlet lifecycle methods..

Q.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.
Q.What is Action Class? What are the methods in Action class?

An Action class is some thing like 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.
Struts Action class is a unit of logic. It is where a call to business function is made. In short the Action class acts like a bridge between client side(user action) and business operation(on server. Some of the important methods of Action class are, execute()generateToken() resetToken() getServlet()
Q.What is the use of ActionForm class, Describe it's Life Cycle?

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 Cycle :
1. Request received by Controller
2. Create or recycle ActionForm
3. Call reset()
4. store ActionForm in proper scope
5. populate ActionForm from Request
6. Validate the ActionForm
7. If errors found then forward back to input attribute page(configured in Action mapping in struts-config.xml) with ActionForm in scope.
If no errors found then call execute() with the ActionForm.

Q.In struts why we use jsp as presentation layer? can we use servlet as presentation layer?

We can separate the business logic from presentation logic2.
It facilitates to write the java code inside a html environment if we use servlets then we need to write the html tags inside out.write() number of times.
it is not possible in all cases and it combines the businesslogic and presentation logic which reduces security
Q. Explain about token feature in Struts?

Use the Action Token methods to prevent duplicate submits:
There are methods built into the Struts action to generate one-use tokens.
A token is placed in the session when a form is populated and also into the HTML form as a hidden property. When the form is returned, the token is validated.
If validation fails, then the form has already been submitted, and the user can be apprised.

ul>
  • saveToken(request)
  • on the return trip,
  • isTokenValid(request)
  • resetToken(request)

    Q.What is the difference between ActionForm and DynaActionForm?

  • # The DynaActionForm bloats up the Struts config file with the xml based definition. This gets annoying as the Struts Config file grow larger.
    # The DynaActionForm is not strongly typed as the ActionForm. This means there is no compile time checking for the form fields. Detecting them at runtime is painful and makes you go through redeployment.
    # ActionForm can be cleanly organized in packages as against the flat organization in the Struts Config file.
    # ActionForm were designed to act as a Firewall between HTTP and the Action classes, i.e. isolate and encapsulate the HTTP request parameters from direct use in Actions. With DynaActionForm, the property access is no different than using request.getParameter( .. ).
    # DynaActionForm construction at runtime requires a lot of Java Reflection (Introspection) machinery that can be avoided.
    # Time savings from DynaActionForm is insignificant. It doesn’t t take long for today s IDEs to generate getters and setters for the ActionForm attributes. (Let us say that you made a silly typo in accessing the DynaActionForm properties in the Action instance. It takes less time to generate the getters and setters in the IDE than fixing your Action code and redeploying your web application)

    Q.Explain Struts navigation flow?
    Struts Navigation flow.
    1) A request is made from previously displayed view.
    2) The request reaches the ActionServlet which acts as the controller.
    The ActionServlet Lookup the requested URI in an XML file (Struts-Config.xml) and determines the name of the Action class that has to perform the requested business logic.
    3)The Action Class performs its logic on the Model Components associated with the Application.
    4) Once The Action has been completed its processing it returns the control to the Action Servlet.
    As part of its return the Action Class provides a key to determine where the results should be forwarded for presentation.
    5)The request is complete when the Action Servlet responds by forwarding the request to the view, and this view represents the result of the action.

    0 comments

    free counters
    Your Ad Here

    Cross Rates Powered by Forex Pros - The Forex Trading Portal.
    java.sun.com jobs etisalat actress hot sex
    Bangalore, 04 March 2008, UAE Telecoms Gaint founds ‘technologia’ in Bangalore to create continuous stream of new innovations. Affordable Website Design
    Free Search Engine Submission
    Free Search Engine Submission
    Submit Your Site To The Web's Top 50 Search Engines for Free! BigDirectory.org - free url submission, online website directory National Directory Free Web Directory Submission - Dotster Directory Link Popularity Building
    We offers advanced Link Popularity Services for small to large static, dynamic and eCommerce websites.
    http://www.links-builder.com
    India Search Engine and Web Directory Superblog Directory
    HOT SEX,NUDE TECHNOLOGIAWORLD SQL JAVA SUN BEA IBM HCL SATYAM TCS CHIRANJEEVI CHIRU PAWAN HANSIKA SANGAVI SNEHA TAMIL SEX MALLU MASALA