Servlet 商品管理系统.docx
- 文档编号:8484491
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:25
- 大小:658.45KB
Servlet 商品管理系统.docx
《Servlet 商品管理系统.docx》由会员分享,可在线阅读,更多相关《Servlet 商品管理系统.docx(25页珍藏版)》请在冰豆网上搜索。
Servlet商品管理系统
Servlet商品管理系统设计
网上商品信息处理
需求分析
编程实现网上商品处理界面,与数据库相连后,实现通过servlet对数据库信息进行操作,包括查询、添加、删除、更新修改记录等,并翻页显示结果。
总体设计
总体设计框架如下图所示:
其中为主页面,分别链接到四个子页面进行不同的操作。
为查询界面,窗体显示商品ID,商品名称,商品数量标识,用户填入想要进行的查询操作后,点击查询按钮,触发QueryServlet中Post函数;
为添加界面,窗体同样显示商品ID,商品名称,商品数量标识,用户必须填入要加入商品的ID号,而商品名称和数量可以为空值,点击添加按钮触发AddServlet中的Post函数;
为修改界面,窗体同样显示商品ID,商品名称,商品数量标识,用户必须填入要修改的商品ID号、商品名称及商品数量,此处不支持填写空值,点击修改按钮触发UpdateServlet中Post函数;
为删除界面,窗体同样显示商品ID,商品名称,商品数量标识,用户可以填入其中一项进行查询,点击删除按钮,触发DeleteServlet中Post函数;
考虑到缺省情况,上述子页面遇到无任何输入的情况下,默认连接数据库,直接查询所有表项,并在中分页显示结果。
详细设计
一、查询模块设计
查询功能分为四种情况,首先,若填入ID不为空,则按照ID查询,调用QueryById()函数;若ID为空,判断name是否为空,若不为空,则按照name查询,调用QueryByName()函数;若name为空,判断num是否为空,若不为空,则按照num查询,调用QueryByNum()函数;最后,若均为空,则为默认情况,调用ShowAll()函数显示数据库中所有表项。
大体框架如下
QueryById()、QueryByName()、QueryByNum()函数均为了实现查询功能,大致相同,仅传递的SQL语句不同;为了使结果能够分页显示,这里将从数据库返回的表项一次填入到自定义类Product实例中,并加入ArrayList容器,用到函数MakeList(),并用session传递到进行分页处理显示。
2、添加模块设计
添加模块主要有两种情况,首先判断JSP中输入的ID是否为空,若为空,因为主键为空,所以添加无效,因此为默认情况,调用ShowAll()函数返回所有表项,分页显示;若不为空,则可执行添加工作,为显示添加成功,此处再次调用ShowAll()显示出你所添加的项已经存在于表项当中。
大致框架如下:
3、修改模块设计
修改模块功能分为两种情况首先,若填入ID不为空,则按照填入消息对SQL语句进行传递,修改后再次查询所有表项,显示出来后证明确实将所需修改的表项进行了修改;若ID为空,为默认情况,调用ShowAll()函数,全部显示。
大致框架如下:
4、删除模块设计
删除功能分为四种情况,首先,若填入ID不为空,则按照ID删除,调用DeleteById()函数;若ID为空,判断name是否为空,若不为空,则按照name删除,调用DeleteByName()函数;若name为空,判断num是否为空,若不为空,则按照num删除,调用DeleteByNum()函数;最后,若均为空,则为默认情况,调用ShowAll()函数显示数据库中所有表项。
大致框架如下:
5、Product类设计
该类的主要功能是将表项封装到一个实例中去,而后将实例一次放入一个list中,而后可以通过检索list来一次输出,因此,Product类中主要有与数据库表项相匹配的变量和相应变量的get、set方法。
六、JSP设计
上述四个JSP子页面的主要功能是为了给用户提供输入框,根据条件获取相应数据库表项,因此JSP大致需一下几个部分:
首先是为了和Servlet相关联的form:
在form中添加入文字和文本域供用户使用,例如:
还有提交按钮,触发Servlet行为,例如:
7、UI界面美化
为了使用户使用时更加美观、方便,这里使用可视化的Dreamweaver软件进行界面设计、图片插入,而后将JSP代码填入具体JSP进行路径、链接配置。
8、环境配置
1、Java运行环境:
MyEclipse,Javawebproject;
2、数据库平台:
MySql;
3、服务器平台:
TomCat6;
关键程序源代码
1、JSP源代码
1)代码:
...............................................
...................................................
2)代码:
...................................................
..................................................
3)代码:
..................................................