Java web之实现当当网网站
运行环境:JDK1.8+tomcat8.4+MySQL5+servlet技术
源码结构
CategoryDAO.java
package com.tarena.dao;import java.sql.SQLException;
import java.util.List;import com.tarena.entity.Category;public interface CategoryDAO {public List<Category> findAll() throws Exception;public List<Category> findByParentId(int pid) throws Exception;
}
DAOFactory.java
package com.tarena.dao;import com.tarena.dao.impl.BookDAOImpl;
import com.tarena.dao.impl.CategoryDAOImpl;
import com.tarena.dao.impl.OrderDAOImpl;
import com.tarena.dao.impl.ReceiveAddressDAOImpl;
import com.tarena.dao.impl.UserDAOImpl;public class DAOFactory {public static UserDAO getUserDAO() {return new UserDAOImpl();}public static CategoryDAO getCategoryDAO() {return new CategoryDAOImpl();}public static ProductDAO getProductDAO() {return new BookDAOImpl();}public static OrderDAO getOrderDAO() {return new OrderDAOImpl();}public static ReceiveAddressDAO getReceiveAddressDAO() {return new ReceiveAddressDAOImpl();}
}
OrderDAO.java
package com.tarena.dao;import com.tarena.entity.Order;
import com.tarena.web.action.cart.CartService;public interface OrderDAO {public void save(Order order,CartService cart) throws Exception;
}
ProductDAO.java
package com.tarena.dao;import java.sql.SQLException;
import java.util.List;import com.tarena.entity.Product;public interface ProductDAO {public List<Product> findByCatId(int cid,int begin,int size) throws Exception;public Product findById(int id) throws Exception;public List<Product> findByHot(int num) throws Exception;public List<Product> findByNew(int num) throws Exception;public List<Product> findByNewHot(int num,long time) throws Exception;
}
ReceiveAddressDAO.java
package com.tarena.dao;
import java.util.List;
import com.tarena.entity.ReceiveAddress;
public interface ReceiveAddressDAO {
public void save(ReceiveAddress addr) throws Exception;public List<ReceiveAddress> findByUserId(int userId) throws Exception;public ReceiveAddress findById(int id) throws Exception;
}
main.jsp
<%@page contentType="text/html;charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>当当图书 – 全球最大的中文网上书店</title><link href="${pageContext.request.contextPath}/css/book.css" rel="stylesheet" type="text/css" /><link href="${pageContext.request.contextPath}/css/second.css" rel="stylesheet" type="text/css" /><link href="${pageContext.request.contextPath}/css/secBook_Show.css" rel="stylesheet" type="text/css" /></head><body>、 <!-- 头部开始 --><%@include file="/common/head.jsp"%><!-- 头部结束 --><div style="width: 962px; margin: auto;"><a href="#" target="_blank"><imgsrc="${pageContext.request.contextPath}/images/default/book_banner_081203.jpg" border="0" /> </a></div><div class="book"><!--左栏开始--><div id="left" class="book_left"><s:action name="categoryAction" namespace="/main" executeResult="true"></s:action></div><!--左栏结束--><!--中栏开始--><div class="book_center"><!--推荐图书开始--><div class=second_c_border1 id="recommend"><s:action name="recommendAction" namespace="/main" executeResult="true"></s:action></div><!--推荐图书结束--><!--热销图书开始--><div class="book_c_border2" id="hot"><s:action name="hotAction" namespace="/main" executeResult="true"></s:action></div><!--热销图书结束--><!--最新上架图书开始--><div class="book_c_border2" id="new"><s:action name="newAction" namespace="/main" executeResult="true"></s:action></div><!--最新上架图书结束--><div class="clear"></div></div><!--中栏结束--><!--右栏开始--><div class="book_right"><div class="book_r_border2" id="__XinShuReMai"><div class="book_r_b2_1x" id="new_bang"><h2 class="t_xsrm">新书热卖榜</h2><div id="NewProduct_1_o_t" onmouseover=""><s:action name="newHotAction" namespace="/main" executeResult="true"></s:action><h3 class="second"><span class="dot_r"> </span><a href="#" target="_blank">更多>></a></h3></div></div></div></div><!--右栏结束--><div class="clear"></div></div><!--页尾开始 --><%@include file="/common/foot.jsp"%><!--页尾结束 --></body>
</html>