1、项目功能演示
<iframe allowfullscreen="true" data-mediaembed="bilibili" frameborder="0" id="gmbE9FiI-1727106487772" src="https://player.bilibili.com/player.html?aid=113187387153972"></iframe>DC00013基于jsp+servlet+javabeen鲜花销售管理系统网上花店网站鲜花销售网上花店管理系统
2、项目功能描述
基于jsp+servlet+javabeen鲜花销售管理系统分为用户和系统管理员两个角色。
2.1 用户功能
1、系统登录、系统注册
2、主页、产品信息、联系我们
3、个人信息修改、修改密码、收货地址维护
4、购物车
5、我的订单
6商品详情、下单
2.2 管理员功能
1、系统登录
2、用户管理
3、商品管理
4、订单管理
5、意见管理
6、系统管理
3、项目运行截图(部分)
4、项目核心代码
4.1 数据库连接
package com.mr.sellsystem.tools;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseConnection {
//包路径
private static String driverName = "com.mysql.jdbc.Driver";
//连接地址
private static String url = "jdbc:mysql://localhost:3305/flowerdata?useUnicode=true&characterEncoding=UTF8";
//数据库用户名密码
private static String uid = "root";
private static String pwd = "root";
public static Connection getConnection() {
Connection conn = null;
try {
Class.forName(driverName);
//通过驱动包方法连接到数据库
conn = DriverManager.getConnection(url, uid, pwd);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
// 释放资源的方法
public static void closeAll(Connection conn, PreparedStatement ps, ResultSet rs) {
try {
if (rs != null){
rs.close();}
if (ps != null){
ps.close();}
if (conn != null){
conn.close();}
} catch (SQLException e) {
e.printStackTrace();
}
}
// 释放资源的方法
public static void closeAll(Connection conn, PreparedStatement ps) {
try {
if (ps != null){
ps.close();}
if (conn != null){
conn.close();}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println(BaseConnection.getConnection());
}
}
4.2 MD5加密
package com.mr.sellsystem.tools;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/*
* MD5 算法
*/
public class MD5 {
// 全局数组
private final static String[] strDigits = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
public MD5() {
}
// 返回形式为数字跟字符串
private static String byteToArrayString(byte bByte) {
int iRet = bByte;
// System.out.println("iRet="+iRet);
if (iRet < 0) {
iRet += 256;
}
int iD1 = iRet / 16;
int iD2 = iRet % 16;
return strDigits[iD1] + strDigits[iD2];
}
// 返回形式只为数字
private static String byteToNum(byte bByte) {
int iRet = bByte;
System.out.println("iRet1=" + iRet);
if (iRet < 0) {
iRet += 256;
}
return String.valueOf(iRet);
}
// 转换字节数组为16进制字串
private static String byteToString(byte[] bByte) {
StringBuffer sBuffer = new StringBuffer();
for (int i = 0; i < bByte.length; i++) {
sBuffer.append(byteToArrayString(bByte[i]));
}
return sBuffer.toString();
}
public static String GetMD5Code(String strObj) {
String resultString = null;
try {
resultString = new String(strObj);
MessageDigest md = MessageDigest.getInstance("MD5");
// md.digest() 该函数返回值为存放哈希值结果的byte数组
resultString = byteToString(md.digest(strObj.getBytes()));
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return resultString;
}
public static void main(String[] args) {
System.out.println(MD5.GetMD5Code("123456"));
//123 202cb962ac59075b964b07152d234b70
//456 250cf8b51c773f3f8dc8b4be867a9a02
}
}
4.3 导入导出公共类
package com.mr.sellsystem.tools;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.Files;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class Excle {
/***
* 导入使用方法
*
String path = Excle.upload(request, response, getServletConfig());
String[] str = {"id","name"};
ArrayList<Object> ar = Excle.readExcel(path,Stars.class,str);
System.out.println(ar);
*/
/***
* 导出使用方法
ArrayList ar = new ArrayList();
Stars ss1 = new Stars(1,"dsa");
Stars ss2 = new Stars(2,"dsa");
Stars ss3 = new Stars(3,"dsadd");
ar.add(ss1);
ar.add(ss2);
ar.add(ss3);
String path = request.getRealPath("/")+"/upload/a.xls";
String[] columns = {"id","name",}
String[] columnsName = {"编号","姓名"};
Excle.outExcle(ar,path,response,columns,columnsName);
*/
public static void outExcle(ArrayList<Object> ar,String path,HttpServletResponse response,String[] columns,String[] columnsName) {
response.reset();
response.setContentType("application/vnd.ms-excel"); //改成输出excel文件
response.setHeader("Content-disposition","attachment; filename=hospital.xls" );
OutputStream os = null;
try {
os = response.getOutputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
WritableWorkbook book = Workbook.createWorkbook(new File(path));
WritableSheet sheet = book.createSheet("Sheet_1", 0);
// id name
int x = 0;
for(String str : columnsName){
Label label = new Label(x, 0, str);
sheet.addCell(label);
x++;
}
for (int i = 0; i < ar.size(); i++) {
Object ob = ar.get(i);
Class c = ob.getClass();
//通过类类型 获取类中的属性
Field[] fields = c.getDeclaredFields();
int num = 0;
for(String str1 : columns){
for (int j = 0; j < fields.length; j++) {
//设置私有属性 在下面可以被访问
fields[j].setAccessible( true );
if(str1.equals(fields[j].getName())){
String str = String.valueOf(fields[j].get(ob));
Label label = new Label(num, i+1, str);
sheet.addCell(label);
num++;
break;
}
}
}
}
// 写入文件中
book.write();
// 关闭流
book.close();
} catch (Exception e) {
e.printStackTrace();
}
Workbook wb;
WritableWorkbook book=null;
try {
wb = Workbook.getWorkbook(new java.io.File(path));
book = Workbook.createWorkbook(os, wb);
} catch (Exception e) {
e.printStackTrace();
}
try {
book.write();
os.flush();
book.close();
}catch(Exception ex){
ex.printStackTrace();
}finally {
if( os != null)
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/***
* 上传文件方法
*
* @param request
* @param response
* @return 文件存放地址
*/
public static String upload(HttpServletRequest request,
HttpServletResponse response,ServletConfig config) {
String sourceFile = "";
/* 初始化JSPSmart变量 */
try {
SmartUpload mySmartUpload = new SmartUpload();
Date date = new Date();
String allowedFilesList = "doc,DOC,pdf,PDF,txt,TXT,html,HTML,htm,HTM,gif,jpg,bmp,txt,doc,xls,htm,html,JPG";
// String allowedFilesList ="mdb";
Files fils = null;
int maxFileSize = 100 * 1024 * 1024;
Request req = null;
// 站点根目录
// 得到servletConfig
mySmartUpload.initialize(config, request, response);
mySmartUpload.setMaxFileSize(maxFileSize); // 上传文件的大小
mySmartUpload.setAllowedFilesList(allowedFilesList);// 允许上传的格式
req = mySmartUpload.getRequest();// 得到JspSmart中的Request对象,提取表单中其他数据
String fileName = "";
String fileExt = "";
try {
// mySmartUpload.setDeniedFilesList("reg,jsp,asp,php");
mySmartUpload.upload();// 上传文件
fils = mySmartUpload.getFiles();
com.jspsmart.upload.File file = fils.getFile(0);
if (!file.isMissing()) {
fileName = date.toLocaleString().replaceAll("-", "")
.replaceAll(":", "").replaceAll(" ", "");
fileName += Double.toString(Math.random()).substring(2)
.substring(0, 4);
// 文件路径
sourceFile = "/upload/km_" + fileName + "."
+ file.getFileExt();
fileExt = file.getFileExt();
// 保存源图
file.saveAs(sourceFile,
com.jspsmart.upload.File.SAVEAS_VIRTUAL);
}
} catch (SmartUploadException e) {
e.printStackTrace();
}
} catch (Exception e) {
// TODO: handle exception
}
sourceFile = request.getSession().getServletContext().getRealPath("") +sourceFile;
return sourceFile;
}
/***
* 参数为 上传好的文件地址 导入excle文件
*
* @param pathname
*/
public static ArrayList readExcel(String pathname, Class c,String[] columns) {
ArrayList ar = new ArrayList();
// 获取excle文件对象
Workbook book;
try {
book = Workbook.getWorkbook(new File(pathname));
// 获得第一个选项卡对象
Sheet sheet = book.getSheet(0);
for (int i = 1; i < sheet.getRows(); i++) {
Object ob = c.newInstance();
Field[] fields = c.getDeclaredFields();
for(int z = 0 ;z<columns.length;z++){
for (int j = 0; j < fields.length; j++) {
// 设置私有属性 在下面可以被访问
fields[j].setAccessible(true);
if( columns[z].equals(fields[j].getName())){
// 判断参数类型 封装数据
if (fields[j].getType().toString().equals(
"class java.lang.String")) {
fields[j].set(ob, sheet.getCell(z, i).getContents());
j = fields.length;
} else if (fields[j].getType().toString().equals(
"class java.lang.Integer")) {
fields[j].setInt(ob, Integer.parseInt(sheet.getCell(z, i).getContents()));
j = fields.length;
}else if (fields[j].getType().toString().equals(
"int")) {
int xxx = Integer.valueOf(sheet.getCell(z, i).getContents());
fields[j].setInt(ob, xxx);
j = fields.length;
} else if (fields[j].getType().toString().equals(
"class java.lang.Float")) {
fields[j].setFloat(ob, Float.valueOf(sheet
.getCell(z, i).getContents()));
j = fields.length;
} else if (fields[j].getType().toString().equals(
"class java.lang.Double")) {
fields[j].setDouble(ob, Double.valueOf(sheet.getCell(z,
i).getContents()));
j = fields.length;
}
}
}
}
ar.add(ob);
}
// 关闭流
book.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ar;
}
}
5、项目文件内容
6、项目获取
6.1 方式一
私信或者扫描下方名片,然后获取项目整体文件。
6.2 方式二
点击此处直接获取项目整体文件。