JSP+SERLVET+JDBC-based development (1)

Source: Internet
Author: User

Long time no use JSP+SERVLET+JDBC this combination, it can be said that since the absence of such work has not been developed this way. Recently did not learn anything, feel the plan is disorderly, take advantage of this weekend write something to find feeling.

This time want to use JSP+SERVLET+JDBC to write a small product display platform demo. function is very simple, is able to display the type of goods, and then according to the type of the type of product can be displayed, said is a small product display platform is more than a change of the demo.

Is the structure of the entire project:

To facilitate decoupling, use the MVC pattern for development, which describes the role of each package:

    1. The Servlet class in which the action is stored, which handles requests from the client
    2. DAO interface specification for storing data persistence layer
    3. Implementation of DAO.IMPL storage data Persistence layer interface
    4. Service Store Business Logic interface
    5. Implementation of SERVICE.IMPL storage business logic interface
    6. The model holds the entity class
    7. Util storage is the tool class
    8. Test class is stored

Various directories under the WebContent:

    1. Resources to store some resource files, such as Css,js,image.
    2. web-inf/jsp Store all JSP pages, the JSP stored under Web-inf is for security reasons, because the JSP stored in the Web-inf directory is not directly accessible through the URL.

This is the structure of the whole project.

Because it is a small demo. Don't want to get too complicated, the whole project is currently designed for two entity classes: type (product type), Goods (product)

The entity classes here use the anemia model, which does not contain business logic.

Here are the code for the two classes:

Type.java

1  Packagemodel;2 3 /*4 * Type entity5  */6  Public classType {7 8     PrivateLong ID;9     PrivateString name;Ten  One      PublicLong getId () { A         returnID; -     } -  the      Public voidsetId (Long id) { -          This. ID =ID; -     } -  +      PublicString GetName () { -         returnname; +     } A  at      Public voidsetName (String name) { -          This. Name =name; -     } -  - @Override -      PublicString toString () { in         return"Type [id=" + ID + ", name=" + name + "]"; -     } to}

Goods.java

1  Packagemodel;2 3 /*4 * Commodity Entities5  */6  Public classGoods {7 8     PrivateLong ID;9     PrivateString name;Ten     PrivateDouble Price; One     PrivateLong Tid;//Product Type (foreign key) A  -      PublicLong getId () { -         returnID; the     } -  -      Public voidsetId (Long id) { -          This. ID =ID; +     } -  +      PublicString GetName () { A         returnname; at     } -  -      Public voidsetName (String name) { -          This. Name =name; -     } -  in      PublicDouble GetPrice () { -         returnPrice ; to     } +  -      Public voidSetprice (Double price) { the          This. Price =Price ; *     } $ Panax Notoginseng      PublicLong Gettid () { -         returnTid; the     } +  A      Public voidSettid (Long tid) { the          This. Tid =Tid; +     } -  $ @Override $      PublicString toString () { -         return"Goods [id=" + ID + ", name=" + name + ", price=" + Price + ", tid=" + tid + "]"; -     } the}

I usually in my own development when the habit of static pages first, and then change the static part of the dynamic can be, after all, there is no front desk to help you do.

Here I use Hbuilder first to write the display page, just for the sake of display, all did not add CSS decoration, the interface looks ugly is not a bit.

Here is the Product Type Display page:

1 <!DOCTYPE HTML>2 <HTML>3     <Head>4         <MetaCharSet= "Utf-8">5         <title>Commodity Display Platform</title>6     </Head>7     <Body>8         <Div>9             <Div><ahref="">Add a Product Type</a></Div>Ten             <!-- One [email protected] A Time: 2015-09-13 - Description: These displays will be replaced with dynamic information -              - the             <Div>Home appliances</Div> -             <Div>Digital</Div> -         </Div> -     </Body> + </HTML>

Product Display page:

1 <!DOCTYPE HTML>2 <HTML>3 4     <Head>5         <MetaCharSet= "Utf-8">6         <title>Commodity</title>7     </Head>8 9     <Body>Ten         <Div> One             <Div><ahref="">Add Item</a></Div> A             <!-- - [email protected] - Time: 2015-09-13 the Description: These displays will be replaced with dynamic information -              - -             <Table> -                 <TR> +                     <th>Serial number</th> -                     <th>Product Name</th> +                     <th>Price</th> A                 </TR> at                 <TR> -                     <TD>1</TD> -                     <TD>Fan</TD> -                     <TD>998</TD> -                 </TR> -             </Table> in         </Div> -     </Body> to  + </HTML>

The operating interface is as follows:

This is just a static page display, here I put the dynamic display of this information in the next blog post.

JSP+SERLVET+JDBC-based development (1)

Related Article

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.