Case 1-Reception category information show
Requirements: When you visit any page, you need to display the classified information.
Technical analysis: include (static inclusion and dynamic inclusion) The static contains the background only generates a class file, and dynamically contains the generation of multiple class files
Ajax Step Analysis:
1. Create Classification Table Category table ' CID ' category ID ' CNAME ' class name
2. Extracting logos and menu parts (head.jsp) page loads on all pages writing functions @include file= "/jsp/head.jsp"%> & nbsp;$ (function () {} jquery Load event Send Ajax request $.post (Url,params,fn,type);
, &NB Sp url:/store/category params:method=findall  FN: Traverse the return value, Each category is encapsulated as an Li tag, inserted into the UL label inside type:json
&NB Sp 3, write Categoryservlet, inherit Baseservlet, write FindAll method
4, call the service, query all the classifications, Categoryservice in the operation call DAO, get all the categories to turn the list into JSON return
5. Include head.jsp in all pages get return value traverse return value
6, each classification encapsulated into an LI tag, inserted into the UL label inside
7, modify the service layer of the code to obtain, to Redis, if obtained to return if not obtained, first go to the MySQL database query out, the list into a JSON into the Redis can
Case 2 latest products and popular products
&NB Sp Requirements: When visiting the homepage, we need to show the latest products and popular products.
technology: Way 1:ajax async Way 2: Sync Using synchronization step analysis (Request forwarding)
1. Create Product List product: pid Product ID pname Product name &nbs P;market_price Market prices Shop_price Mall price pimage picture path pdate shelf time
Is_hot is popular Pdesc product Details pflag physical deletion status 0 not under frame 1 the ID foreign key of the lower frame CID classification
2. Access to the Project home page, request forwarding Indexservlet Indexservlet using the default index processing
Call Productservice query for hot goods and the latest products, each return a list put two list into the request domain, request forward to/jsp/index.jsp
3.: Traverse the data on the page
Case 3-Single Item details
Requirements: Click on each item on the home page to display the details of this product (product_info.jsp)
Step Analysis:
1. Add a hyperlink to each item <a href= "/store/product?method=getbyid&pid=xxx" >yy</a>
2. Write Productservlet, Inherit Baseservlet, write GetByID get product PID call service get a product return value: Product request forwarded to product_info.jsp
3.service, DAO
4. Show the goods in product_info.jsp
Case 4-pagination display of classified items
Requirements: Click on the menu bar of a category, the classification of products, pagination display (default first page)
Technical Analysis:
1, paging page required data current page Total pages total number of records per page limit m,n limit (current page-1) * Number of bars per page, number of bars displayed per page
limit m,n 语法 /*当没有指定位置偏移量时,只取4条时,可以这样写*/ SELECT
*
FROM
YourTableName LIMIT 4;
where m refers to the beginning of the record index, starting from 0, representing the first record, n means starting from section m+1 and taking N.
Step Analysis:
1. Modify the hyperlink for each category on the head.jsp
<a href= "/store/product?method=findbypage&pagenumber=1&cid=xxx" >
2. Writing the Findbypage method in Cateservlet
Get PageNumber
Get CID
Set pagesize
Call service to get paged data return value: Pagebean
Put the Pagebean in the request domain, requesting forwarding/jsp/product_list.jsp
3. Write the service:
return value: Pagebean
Create a Pagebean
Set the data required for the current page
Call DAO
Set total number of records
Call DAO
4.dao
5. Display items on the jsp/product_list.jsp
Javaweb Project--Online shop (6-2)