The first lesson - Introduction - Your first struts program
Written by caiyi0903 (willpower), 2004.6.22
You will create an analog program to add an employee to the database. Users need to belong to the name and age of the employee. The first lesson content introduction
Installing environmental data transfer object (Data Transfer Object) Actionformweb.xmlstruts-config.xmlapplicationResources Lab Usage 1 Install Tomcat Download and install the latest stable version of Tomcat, preferably 4.0 or more version: Tomcat download address: http: // Jakarta.apache.org/site/binindex.cgitomcat is easy, this article does not describe too much. 2 Create a web application directory created a directory in Tomcat's WebApps called "RR_LESSON_1". The directory structure is as follows:
WebApps | | rr_lesson_1 | | --- Web-INF | | --- Classes | | | --- Net | | - Reumann | --- LIB | --- SRC | --- Net | - Reumann
3 Add struts file
Download and install Struts:
The Struts download address is as follows:
http://www.apache.org/dist/jakarta/struts/binaries/ (Binary Version)
This course assumes that you use the Struts1.1 version.
After downloading, decompress an arbitrary place, it is best to be outside the Tomcat directory.
Copy Struts in the RR_LD file to the RR_LESSON_1 application:
Enter {strutsDirectory} / control / struts-el / lib directory, copy the following .tld file to the rr_lesson_1 / web-inflicity:
C.TLD
Struts-bean-el.tld
Struts-html-el.tld
Struts-logic-el.tld
Copy Struts in the .jar file to the RR_LESSON_1 application:
Copying the following .jar files into the rr_lesson_1 / web-inf / lib directory from {strutsdirectory} / limited :jar files to the rr_lesson_1 / web-inf / lib directory:
Commons-beanutils.jar
Commons-Collects.jar
Commons-digester.jar
Commons-logging.jar
JSTL.jar
Standard.jar
Struts-el.jar
Struts.jar
4 Create a DTO (Data Transfer Object)
Since we want to handle the employees we will insert, then we need a way to save information about this employee. We need a class to express our employees. Here is the use of the Bean class, it has a pair of Getter and Setter methods.
Since this object will transfer some of the store information in our application to another, it is called a data transfer object or a value object (Data Transfer Object).
Create EMPLOYEDTO:
Package net.reumann;
Public class employeedto {
PRIVATE STRING NAME;
PRIVATE INT AGE;
Public void setname (String name) {
THIS.NAME = Name;
}
Public void setage (int Age) {
THIS.AGE = AGE;
Public string getname () {
Return Name;
}
Public int getage () {
Return Age;
}
}
5 Create business services
The most complicated place in a web application may be business logic. Here we will create an EmployeService class to handle a small amount of business logic. Create EMLOYESERVICE:
package net.reumann; public class EmployeeService {public EmployeeDTO insertEmployee (EmployeeDTO employee) {// do some operations here and the insertion operation, such as @: EmployeeDAO.insertEmployee (employee); return employee;}}