struts1.x Series Tutorials (1): Developing the first Struts program with MyEclipse

Source: Internet
Author: User
Tags character set create database

This series of tutorials will detail the fundamentals and usage of struts 1.x, and readers can see the same points and differences between struts 1.x and struts 2.x in the Struts 2 series tutorial.

First, this article gives the program to realize what function

Mystruts is a procedure for inputting and querying product information. For convenience, the product information table in this example includes only three fields for the product ID, product name, and product price. The main functions of mystruts are as follows:

1. Accept the Product ID, product name, and product price entered by the user.

2. Verify the legality of these fields. If the input of some fields is not appropriate (for example, if you do not enter a product ID), the program forward to an information display page and displays the reason for the error.

3. If the user enters the correct field values, the program saves the field values to the database and displays the Save success information.

4. The user enters the product name, and carries on the fuzzy inquiry according to the product name. If there are product information that meets the requirements. The program displays information about the products in a tabular format, displaying the number of records. If no records are found, "there is no record to meet the requirements!" Information.

II. preparation prior to the preparation of the procedure

1. Establishing a Database

Before you write a program, you need to create a database (struts) and a table (t_products), and the SQL script to build the database and table is as follows:

# Build Database Struts
CREATE DATABASE IF not EXISTS struts DEFAULT CHARACTER SET GBK;

# Set up table T_products
CREATE TABLE IF not EXISTS struts.t_products (
product_id varchar (4) Not NULL,
Product_Name varchar (m) not NULL,
Price float is not NULL,
PRIMARY KEY (product_id)
) Engine=innodb DEFAULT CHARSET=GBK;

2 Establish a support struts1.x of the Samples project

Using MyEclipse to build a samples project (Web Engineering), the samples project does not yet support struts1.x (without introducing the corresponding struts jar package, Struts-config.xml files and other configuration related to struts. However, in MyEclipse this does not require us to join by hand. You can do this automatically by using the MyEclipse New Struts Capabilities dialog box.

Select the Samples project first, then select "MyEclipse" > "New Struts Capabilities" in the right-click menu to launch the New Struts Capabilities dialog box. The following changes are required for the default settings:

(1) Change struts specification to struts 1.2.

(2) Change the base package for new classes to struts.

(3) Change the default application resources to struts. Applicationresources.

After the change, the New Struts Capabilities dialog box is shown in Figure 1.

Figure 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.