• 大小: 2.03MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-11
  • 语言: Java
  • 标签: servlet  jsp  

资源简介

jsp+servlet实现网上商城(无任何主流框架)整体项目我在实现的时候并未使用任何框架,运用了工程化的思想和手段,例如将抽象的基类(JavaBean)封装到mall.JavaBean中,将对数据库的查询,增删改的具体实现(包括SQL语句)封装到mall.dao中,将承担事务处理的Servlet封装到mall. Servlet中。同时使用了JTSL标签和迭代标签,以及request、response、response .sendRedirect、cookies等JSP内置对象,使用一些了JSP标记例如include标记。

资源截图

代码片段和文件信息

package mall.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import mall.JavaBean.JDBCU;
import mall.JavaBean.commodity;

public class cartDao {
public boolean insert(commodity commodity) {
Connection cn = null;
Statement st = null;
try {
cn = JDBCU.getConnection();
String sql = “insert into cart(oid name price flag count orderDate,orderCustomerid) values(????????)“;
PreparedStatement preSt = cn.prepareStatement(sql);
preSt.setString(1 “O5“);
preSt.setString(2 commodity.getName());
preSt.setDouble(3 commodity.getPrice());
preSt.setString(4 commodity.getFlag());
preSt.setDouble(5 commodity.getCount());
preSt.setString(6 commodity.getOrderDate());
preSt.setString(6 commodity.getOrderCustomer());
preSt.setString(6 commodity.getId());
  int num = preSt.executeUpdate();
  if(num > 0)
  { 
  return true; 
  }
  return false;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
JDBCU.release(st cn);
}
return false;
}

public commodity find(String id){
Connection cn = null;
Statement st = null;
ResultSet rs = null;
try {
cn = JDBCU.getConnection();
st = cn.createStatement();
commodity commodity = new commodity();
String sql = “select * from cart where id=‘“+ id +“‘ “;
rs = st.executeQuery(sql);
while(rs.next()){
commodity.setId(rs.getString(“id“));
commodity.setCount(rs.getDouble(“count“));
}
return commodity;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
JDBCU.release(rs st cn);
}
return null;
}
public ArrayList findAll(String username){
Connection cn = null;
Statement st = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try {
cn = JDBCU.getConnection();
st = cn.createStatement();
if(username != “ “){
String sql = “select * from cart where orderCustomer = ‘“+username+“‘“;
rs = st.executeQuery(sql);
}else{
String sql = “select * from cart“;
rs = st.executeQuery(sql);
}


while(rs.next()){
commodity commodity = new commodity();
commodity.setId(rs.getString(“id“));
commodity.setName(rs.getString(“name“));
commodity.setPrice(rs.getDouble(“price“));
commodity.setFlag(rs.getString(“flag“));
commodity.setCount(rs.getDouble(“count“));
commodity.setOrderDate(rs.getString(“orderDate“));
commodity.setOrderCustomer(rs.getString(“orderCustomer“));
lis

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-06-19 10:36  1830200010 李国民 天师大网上商城\
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\
     文件        3374  2020-06-19 10:29  1830200010 李国民 天师大网上商城\Prj\mysqlforonlinemall.sql
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\
     文件        1089  2020-06-18 10:10  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.classpath
     文件        1043  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.project
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\
     文件         567  2019-05-31 20:10  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\.jsdtscope
     文件         276  2020-06-18 19:59  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\org.eclipse.core.resources.prefs
     文件         364  2019-05-31 20:10  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\org.eclipse.jdt.core.prefs
     文件         650  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\org.eclipse.wst.common.component
     文件         305  2019-07-15 12:34  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2019-05-31 20:10  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2019-05-31 20:10  1830200010 李国民 天师大网上商城\Prj\OnlineMall\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\dao\
     文件        5725  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\dao\cartDao.class
     文件        6247  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\dao\commodityDao.class
     文件        6791  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\dao\userDao.class
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\JavaBean\
     文件        1681  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\JavaBean\commodity.class
     文件         578  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\JavaBean\JDBCU$TextUtils.class
     文件        1687  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\JavaBean\JDBCU.class
     文件        1487  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\JavaBean\user.class
     目录           0  2020-06-19 10:40  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\servlet\
     文件        1821  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\servlet\addgoodInfo.class
     文件        2615  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\servlet\addorders.class
     文件        2585  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\servlet\login.class
     文件        2427  2020-06-19 09:54  1830200010 李国民 天师大网上商城\Prj\OnlineMall\build\classes\mall\servlet\register.class
............此处省略64个文件信息

评论

共有 条评论