基于javaweb的JSP+Servlet网上书城+后台管理系统(java+jsp+servlert+mysql+ajax)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

110023032402

120023032402

130023032402

140023032402

150023032402

基于javaweb的JSP+Servlet网上书城+后台管理系统(java+jsp+servlert+mysql+ajax)

1
2
3
4
5
6
7
前台:http://localhost:8080
user1 123456
user2 123456
user3 123456

后台:http://localhost:8080/goods/admin
admin 123456

一、项目简述

功能: 前台: * 用户模块 * 分类模块 * 图书模块 * 购物车模块 * 订单模块

后台: * 管理员模块 * 分类管理模块 * 图书管理模块 * 订单模块

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP + C3P0+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload等等。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


public class AdminAddBookServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");

/*
* 1. commons-fileupload的上传三步
*/
// 创建工具
FileItemFactory factory = new DiskFileItemFactory();
/*
* 2. 创建解析器对象
*/
ServletFileUpload sfu = new ServletFileUpload(factory);
sfu.setFileSizeMax(80 * 1024);//设置单个上传的文件上限为80KB
/*
* 3. 解析request得到List<FileItem>
*/
List<FileItem> fileItemList = null;
try {
fileItemList = sfu.parseRequest(request);
} catch (FileUploadException e) {
// 如果出现这个异步,说明单个文件超出了80KB
error("上传的文件超出了80KB", request, response);
return;
}

/*
* 4. 把List<FileItem>封装到Book对象中
* 4.1 首先把“普通表单字段”放到一个Map中,再把Map转换成Book和Category对象,再建立两者的关系
*/
Map<String,Object> map = new HashMap<String,Object>();
for(FileItem fileItem : fileItemList) {
if(fileItem.isFormField()) {//如果是普通表单字段
map.put(fileItem.getFieldName(), fileItem.getString("UTF-8"));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
		 */
PageBean<Order> pb = orderService.myOrders(user.getUid(), pc);
/*
* 5. 给PageBean设置url,保存PageBean,转发到/jsps/book/list.jsp
*/
pb.setUrl(url);
req.setAttribute("pb", pb);
return "f:/jsps/order/list.jsp";
}
}
package cn.itcast.goods.user.web.servlet;




/**
* 用户模块WEB层
*
*/
public class UserServlet extends BaseServlet {
private UserService userService = new UserService();

/**
* ajax用户名是否注册校验
* @param req
* @param resp
* @return
* @throws ServletException
* @throws IOException
*/
public String ajaxValidateLoginname(HttpServletRequest req, HttpServletResponse resp)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
	String url = getUrl(req);
/*
* 3. 获取查询条件,本方法就是cid,即分类的id
*/
String press = req.getParameter("press");
/*
* 4. 使用pc和cid调用service#findByCategory得到PageBean
*/
PageBean<Book> pb = bookService.findByPress(press, pc);
/*
* 5. 给PageBean设置url,保存PageBean,转发到/jsps/book/list.jsp
*/
pb.setUrl(url);
req.setAttribute("pb", pb);
return "f:/jsps/book/list.jsp";
}

/**
* 按图名查
* @param req
* @param resp
* @return
* @throws ServletException
* @throws IOException
*/
public String findByBname(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
/*
* 1. 得到pc:如果页面传递,使用页面的,如果没传,pc=1
*/
int pc = getPc(req);
/*
* 2. 得到url:...
*/
String url = getUrl(req);
/*
* 3. 获取查询条件,本方法就是cid,即分类的id
*/
String bname = req.getParameter("bname");
/*
* 4. 使用pc和cid调用service#findByCategory得到PageBean
*/
PageBean<Book> pb = bookService.findByBname(bname, pc);
/*
* 5. 给PageBean设置url,保存PageBean,转发到/jsps/book/list.jsp
*/
pb.setUrl(url);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	/*
* 2. 得到url:...
*/
String url = getUrl(req);
/*
* 3. 获取查询条件,本方法就是cid,即分类的id
*/
String bname = req.getParameter("bname");
/*
* 4. 使用pc和cid调用service#findByCategory得到PageBean
*/
PageBean<Book> pb = bookService.findByBname(bname, pc);
/*
* 5. 给PageBean设置url,保存PageBean,转发到/jsps/book/list.jsp
*/
pb.setUrl(url);
req.setAttribute("pb", pb);
return "f:/jsps/book/list.jsp";
}

/**
* 多条件组合查询
* @param req
* @param resp
* @return
* @throws ServletException
* @throws IOException
*/
public String findByCombination(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
/*
* 1. 得到pc:如果页面传递,使用页面的,如果没传,pc=1
*/
int pc = getPc(req);
/*
* 2. 得到url:...
*/
String url = getUrl(req);
/*
* 3. 获取查询条件,本方法就是cid,即分类的id
*/
Book criteria = CommonUtils.toBean(req.getParameterMap(), Book.class);
/*
* 4. 使用pc和cid调用service#findByCategory得到PageBean
*/
PageBean<Book> pb = bookService.findByCombination(criteria, pc);
/*
* 5. 给PageBean设置url,保存PageBean,转发到/jsps/book/list.jsp
*/
pb.setUrl(url);
req.setAttribute("pb", pb);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 * @throws IOException
*/
public String load(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String bid = req.getParameter("bid");//获取链接的参数bid
Book book = bookService.load(bid);//通过bid得到book对象
req.setAttribute("book", book);//保存到req中
return "f:/jsps/book/desc.jsp";//转发到desc.jsp
}

/**
* 按分类查
* @param req
* @param resp
* @return
* @throws ServletException
* @throws IOException
*/
public String findByCategory(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
/*
* 1. 得到pc:如果页面传递,使用页面的,如果没传,pc=1
*/
int pc = getPc(req);
/*
* 2. 得到url:...
*/
String url = getUrl(req);
/*
* 3. 获取查询条件,本方法就是cid,即分类的id
*/
String cid = req.getParameter("cid");
/*
* 4. 使用pc和cid调用service#findByCategory得到PageBean
*/
PageBean<Book> pb = bookService.findByCategory(cid, pc);
/*
* 5. 给PageBean设置url,保存PageBean,转发到/jsps/book/list.jsp
*/
pb.setUrl(url);
req.setAttribute("pb", pb);
return "f:/jsps/book/list.jsp";
}

/**
* 按作者查
* @param req
* @param resp
* @return
* @throws ServletException
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	 * @param req
* @param resp
* @return
* @throws ServletException
* @throws IOException
*/
public String findByCombination(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
/*
* 1. 得到pc:如果页面传递,使用页面的,如果没传,pc=1
*/
int pc = getPc(req);
/*
* 2. 得到url:...
*/
String url = getUrl(req);
/*
* 3. 获取查询条件,本方法就是cid,即分类的id
*/
Book criteria = CommonUtils.toBean(req.getParameterMap(), Book.class);
/*
* 4. 使用pc和cid调用service#findByCategory得到PageBean
*/
PageBean<Book> pb = bookService.findByCombination(criteria, pc);
/*
* 5. 给PageBean设置url,保存PageBean,转发到/jsps/book/list.jsp
*/
pb.setUrl(url);
req.setAttribute("pb", pb);
return "f:/jsps/book/list.jsp";
}
}
package cn.itcast.goods.admin.web.servlet;




项目链接:
https://javayms.github.io?id=241422292105200ex
https://javayms.pages.dev?id=241422292105200ex