一.后台功能的实现
1.实现后台登录
2.对商品分类的的管理(实现增删改查)
分页查询:
Dao层:
public List
String sql="select * from product limit ?,?";
QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
return qr.query(sql, new BeanListHandler
}
public int count() throws SQLException{
String sql="select count(*) from product";
QueryRunner runner=new QueryRunner(DataSourceUtils.getDataSource());
return ((Long)runner.query(sql,new ScalarHandler())).intValue();
}
Service层
ProductDao pd=new ProductDao();
public List
try {
return pd.findProducts((currentPage-1)*pageSize, pageSize);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public int getMaxPage(int pageSize){
int totalCount;
try {
totalCount=pd.count();
return totalCount % pageSize > 0 ? totalCount / pageSize + 1 : totalCount / pageSize;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
Servlet层:
private ProductService ps = new ProductService();
private final int pageSize = 10;
private boolean runable=true;
public void list(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int currentPage = 1;
if (request.getParameter("currentPage") != null) {
currentPage = Integer.parseInt(request.getParameter("currentPage"));
}
int maxPage = ps.getMaxPage(pageSize);
List
request.setAttribute("list", list);
request.setAttribute("currentPage", currentPage);
request.setAttribute("maxPage", maxPage);
request.getRequestDispatcher("/admin/product/list.jsp").forward(
request, response);
}
前台:
先要导入标签库:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:choose>
<c:when test="${currentPage eq 1}">
上一页
c:when>
<c:otherwise>
<a href="${pageContext.request.contextPath}/product?currentPage=${currentPage - 1}&&method=list">上一页a>
c:otherwise>
c:choose>
<c:forEach begin="1" end="${maxPage}" var="index">
<c:if test="${index eq currentPage}">
<a href="script:void(0)" style="color:red">${index}a>
c:if>
<c:if test="${index ne currentPage}">
<a href="${pageContext.request.contextPath}/product?currentPage=${index}&&method=list">${index}a>
c:if>
c:forEach>
<c:choose>
<c:when test="${currentPage eq maxPage}">
下一页
c:when>
<c:otherwise>
<a href="${pageContext.request.contextPath}/product?currentPage=${currentPage + 1}&&method=list">下一页a>
c:otherwise>
c:choose>
3.对商品的管理(实现增删改查)
4.实现对订单详情的增删改查
5.自定义标签库
xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>JSTL 1.1 functions librarydescription>
<display-name>JSTL functionsdisplay-name>
<tlib-version>1.1tlib-version>
<short-name>myfnshort-name>
<uri>http://www.bukeng.comuri>
<function>
<description>
select all categories
description>
<name>findAllCategoriesname>
<function-class>com.dao.CategoryDaofunction-class>
<function-signature>java.util.List findAllCategories()function-signature>
function>
taglib>
二.前台实现
1. 登录注册功能的实现(运用到了session,cookie,邮箱验证)
2. 导航条的实现(使用了ajax技术,redis缓存服务器)
3. 对首页的查询
4. 实现分类查询功能
5. 实现购物车功能
6.实现在线支付功能
7.实现Filter拦截器