|
-
Now create a new Java class. This class will be the main data bean for this project.
- Right click on src, and select New => Class
- For the name, call it PersonalData.
- For the package, put in "pdata."
- Select Finish
NOTE: By convention, Class names begin with an upper case letter, and package names begin with a lowercase letter.
-
Create another class and name it PersonalDataAction with the same package name, and save it. This class will be the main Struts action for this project.
-
Create one more class, and name it Constants. This class will hold global constants for the project.
-
Setup libraries for the project
- Right click the project name and select Properties
- Select the Libraries tab and then Add External Jars
- Navigate to Tomcat Home/common/lib
- Select servlet-api.jar and jsp-api.jar, Click Open.
- Select Add Jars, and select struts-core-1.3.5.jar from WebRoot/WEB-INF/lib, Click OK.
-
Implement the PersonalData bean
-
Add necessary imports
import org.apache.struts.action.ActionForm;
import java.io.Serializable;
-
Change inheritance
- Add extends ActionForm
- Add implements Serializable
-
Add member variables. These will correspond to the form we implement in JSP later.
private String firstname;
private String lastname ;
private String address ;
private String city ;
private String state ;
-
Add the getters and setters for the class members.
-
By hand, you would add a get method and a set method for each member variable. For more information on this,
look up standard naming conventions and methods for Java Beans.
-
In Eclipse, you can right click on the edit area, and select Source => Generate Getters and Setters.
-
Select all member variables and hit OK.
-
Save File
-
Implement the Constants class
-
Create a constant for success and failures of a Struts action
public static final String SUCCESS_KEY = "success";
public static final String FAILURE_KEY = "failure";
-
Save File
NOTE: By convention, static finals are in all upper case.
Page 1 Page 3 Page 4
|
|