JBUILDER2005 Struts Depth Experience upgrade

Source: Internet
Author: User
Tags add functions key sql new features

  Replace switch.jsp with the action controller

We introduced the process of the user Login module in JBuilder advanced development, where switch.jsp acts as a central processor for business processing and page forwarding. Because the design of JSP is designed to implement the logic of the page, and here we actually "perverse", the JSP used as business processing and page forwarding, is obviously not appropriate. Our original switch.jsp body concurrently several posts: receives the LOGIN.JSP page the form data, the inquiry database, the forwarding page, like a detail, has the transgression suspicion the "housekeeper" to take over all things, the procedure does not have the stratification, the logic appears very not clear, resembles a hodgepodge.

In fact, the servlet itself is more suitable for the development of the functions of switch.jsp, but in the jbuilder of the advanced development of the "servlet", we did not use the servlet treatise, is because we want to replace switch.jsp more perfectly in this topic from a higher perspective.

The switch.jsp function can be decomposed through the struts framework, switch.jsp can be realized through the actionform mechanism through <jsp:useBean> obtaining the form data of the login page; switch.jsp query T_ User data table, which determines whether users are legitimate users can handle in the action's Execute () When failed to pass the validation to the Fail.jsp page, if an exception to the error.jsp page, when the user through the verification to the Welcome.jsp page, you can through the action Actionforward to achieve multiple export switching.

  Add a library Management module

The reality of the library Management module, should include the book to increase, delete, change, check the function, due to space limitations, we only provide new functions of books. The database must provide a table for saving information about the book, which is named T_book and is structured as shown in Figure 4:


Fig. 4 T_book Table structure

We are fully using the struts framework to achieve the new features of the book, JBuilder provides an excellent struts visual design tool (Struts Config Editor), where action designer can very vividly describe a business function operation process, Let's preview the program structure of the new business of the book through this visual designer, as shown in Figure 5:


Figure 5 new book struts process
bookadd.jsp: A book entry interface where you'll learn about struts tags and resource files.

Bookactionform: Implemented by the Bookactionform class, saves the data submitted by the Bookadd.jsp form. Here, you will learn how to create a actionform,actionform how to test the validity of data.

/bookinsertaction: Implemented by the Bookinsertaction class, which is the business controller, is responsible for saving the new books in Bookactionform to the Database T_book table, and to the Insertsuccess.htm page.

  Advance preparation

Through File->new Project ... Create a new project called Bookstore, and create a Web module called Webmodule under the project that overwrites the original code of the JBuilder the advanced development of the servlet for the new project.

Use SQL Plus to run the following SQL statement to create the T_book table:

Code Listing 5 Creating an SQL statement for the T_book table

1. CREATE TABLE T_book (
2. book_id VARCHAR2 (a) NOT NULL,
3. ISBN VARCHAR2 (%) not NULL,
4. Book_name VARCHAR2 (m) not NULL,
5. AUTHOR VARCHAR2 (50),
6. Create_date CHAR (8),
7. Constraint Pk_t_book primary KEY (BOOK_ID)
8.);

From this SQL, we can see that book_id is the primary key of the table, so it is not allowed to repeat, and the ISBN and book_name two fields are not allowed to be empty. They determine the rules for data validation when books are added.

Again, we need to add the necessary classes to the class library for this new project.



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.