Home » struts1

# Category Archives: struts1

## Struts1 Spring and Hibernate Integration

Register.jsp

Failure.jsp

Success.jsp

web.xml

struts-config.xml

applicationContext.xml

RegisterForm.java

RegisterAction.java

Register.hbm.xml

Register.java

RegisterDao.java

RegisterDao.Impl.java

RegisterBoImpl.java

RegisterBo.java

## Struts1 and Spring Configuration Steps

1. While integrating struts with spring provides business logic in the form of beans and the MVC layer will be provided by struts.
2. In the order to integrate struts of spring we need plugin class called contextLoaderPlugin or contextLoaderLisenar class these are given in org.spfw.web.struts.jar.*.
3. We need to configure the above plugin in struts-config.xml file with plugin element.
4. In the integration the spring cfg.xml file name should <any-name.xm> and put in under of WEB-INF folder.
5. Delegating action proxy class is responsible to communicate struts-config.xml file to spring-confg.xml file.
6. In order to move the control form s-c.xml file.to spring cfg file we need to make use of predefined class called delighting Action Proxy class it is given in org.spfw.web.struts.* package.
7. While integrating struts with spring the action class of struts must be cfg in the spring cfg.xml file.
8. Action class of struts will using the object of spring bean to call the business logic so Action class is called caller bean and spring bean is all dependent object.

## Directory Structure of Struts1 Based Web Application

Following is the structure of struts1 web application

1. Create Project Name.
2. Under of Project folder create Web-INF folder.
3. Under of Web-inf folder create web.xmlstruts-config.xml file,all tld files, validator-rules.xml file and validation.xml file.
4. Under of classes folder put All paickages of action class and form beans class,also put Application.resources.property files.
5. In lib foalder put all struts releated jar files.

## DynaAction Form

Struts 1.2 mandated that every HTML form in the JSPs have an associated ActionForm. Struts 1.1 changed all that with the introduction of
DynaActionForm – dynamic ActionForm as the name suggests. DynaActionForm is defined in the struts-config.xml as a form-bean. A sample
DynaActionForm is shown below Sample DynaActionForm

There are two things

1. For a DynaActionForm, the type attribute of the form-bean is always org.apache.struts.action.DynaActionForm.
2. A regular ActionForm is developed in Java and declared in the struts-config.xml. The JavaBeans properties of a regular ActionForm are created by first defining the instance variable and then adding a getter and setter for that instance variable. A DynaActionForm has no associated Java class. Its JavaBeans properties are created by adding the <form-property> tag in Struts Config file (and also declaring its Java type). In above RegisterForm is declared as a DynaActionForm with JavaBeans properties. The type attribute of the <form-property> is the fully qualified Java class name for that JavaBeans property; it cannot be a primitive. For instance int is not allowed. Instead you should use java.lang.Integer. You can also initialize the form property,so that the html form shows up with an initial value.

## Types of Form Beans in Struts1

The FormBean that is generated by struts forward software dynamically based on the details we provide in struts-config.xml file is called Dynamic Form Beans. There are six types of Form Beans Classes.

1 validationForm.
2 DynavalidatorForm.
3 ActionForm.
4 DynaActionForm.
5 ValidatorActionForm.
6 DynaValidatorActionForm.

## Types of Built actions in Struts1

There are following built in actions in Struts1

1 Action Class.
2 Dispatch Action Class.
3 Lookup Dispatch Action.
4 Forward Action Class.
5 Include Action Class.
6 Switch Action Class.
7 Locale Action Class.

## Declarative validation example

When ever we deploy this program in any server this program we used Declarative validation logic those validation declare in validation.xml files under of tags. We declare form bean names, fields property depends with the help of ApplicationResources.properties file this generate any errors messages again with the help of tags in jsp pages it display errors messages.

Index.jsp

Success.jsp

Fail.jsp

Web.xml

Struts-config.xml

Validation.xml

ApplicationResources.properties

## DynaAction form example

register.jsp

Failure.jsp

Fail.html

web.xml

struts-config.xml

validation.xml

Register.java

ApplicationResources.properties

## Work Flow of Struts1 framework

1. User submits the request having data from login.jsp form.
2. Through the web.xml ActionServlet traps the request.
3. ActionServlet uses struts-config.xml file entries to decide appropriate action class and FormBean class to process the request.
4. Forward Software create form beans class object and populates received form data to form bean class object.
5. Forward create Action class object.
6. Forward calls execute method of action class.
7. Action class interact model component.
8. Model component execute business logic.
9. Business logic execution result comes to action class execute().
10. Action class transfer the control to the controller ActionServlet.
11. Based on ActionForward statement available in struts-config.xml file controle goes to result.jsp.
12. Presentation logic in result.jsp pages execute and formatted result goes to browser as response.

## Steps to Develop a Program

Following are the steps to develop a struts1 bases programs

1. Gather and define the application requirement.
2. Define and developed each screen requirement in terms of the data collected and displayed.
3. Determine all the access path for each screen.
4. Determine the ActionMapping that correlate to the application business logic.
5. Create the ActionForms with depend properties from the screen requirements this(include the validation portion as well.
6. Develop Actions to be called by ActionMappings that in turn call the appropriate helpers and forward to jsp.
7. Develop the application business logic (Beans,ejb,etc)
8. Create jsp to match the workflows using ActionMappings.
9. Build the appropriate configuration file this includes struts-config.xml and web.xml.
10. Build,test,deploy.
Managed by MochaHost - Fast & Easy WordPress Hosting