Servlet商品管理系统Word格式文档下载.docx
《Servlet商品管理系统Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Servlet商品管理系统Word格式文档下载.docx(25页珍藏版)》请在冰豆网上搜索。
大致框架如下:
3、修改模块设计
修改模块功能分为两种情况首先,若填入ID不为空,则按照填入消息对SQL语句进行传递,修改后再次查询所有表项,显示出来后证明确实将所需修改的表项进行了修改;
若ID为空,为默认情况,调用ShowAll()函数,全部显示。
4、删除模块设计
删除功能分为四种情况,首先,若填入ID不为空,则按照ID删除,调用DeleteById()函数;
若ID为空,判断name是否为空,若不为空,则按照name删除,调用DeleteByName()函数;
若name为空,判断num是否为空,若不为空,则按照num删除,调用DeleteByNum()函数;
大致框架如下:
5、Product类设计
该类的主要功能是将表项封装到一个实例中去,而后将实例一次放入一个list中,而后可以通过检索list来一次输出,因此,Product类中主要有与数据库表项相匹配的变量和相应变量的get、set方法。
六、JSP设计
上述四个JSP子页面的主要功能是为了给用户提供输入框,根据条件获取相应数据库表项,因此JSP大致需一下几个部分:
首先是为了和Servlet相关联的form:
<
formname="
query"
method=postaction="
servlet/QueryServlet"
>
<
/form>
在form中添加入文字和文本域供用户使用,例如:
inputtype="
text"
name="
id"
size=30>
还有提交按钮,触发Servlet行为,例如:
submit"
value="
Query"
7、UI界面美化
为了使用户使用时更加美观、方便,这里使用可视化的Dreamweaver软件进行界面设计、图片插入,而后将JSP代码填入具体JSP进行路径、链接配置。
8、环境配置
1、Java运行环境:
MyEclipse6.5,Javawebproject;
2、数据库平台:
MySql;
3、服务器平台:
TomCat6;
关键程序源代码
1、JSP源代码
1)Main.jsp代码:
...............................................
body>
divalign="
center"
/div>
tablewidth="
606"
height="
435"
border="
0"
tr>
tdheight="
334"
colspan="
4"
imgsrc="
images/background.jpg"
width="
627"
333"
/>
/td>
/tr>
tdwidth="
155"
95"
ahref="
Query.jsp"
images/Query.jpg"
150"
85"
/a>
146"
index.jsp"
images/Add.jpg"
134"
Update.jsp"
images/Update.jpg"
153"
Delete.jsp"
images/Delete.jpg"
/table>
pclass="
STYLE1"
&
nbsp;
/p>
/body>
...................................................
2)Query.jsp代码:
add"
method="
Post"
action="
671"
342"
2"
164"
images/ID.jpg"
160"
80"
459"
>
77"
images/name.jpg"
td>
name"
73"
images/num.jpg"
num"
82"
查询"
..................................................
3)Add.jsp代码:
4)Update.jsp代码:
servlet/UpdateServlet"
添加"
5)Delete.jsp代码:
delete"
servlet/DeleteServlet"
删除"
6)Result.jsp代码:
%
intcurrentPage=1;
intfirstCount=1;
intendCount=1;
Listlist=null;
list=(ArrayList)session.getAttribute("
list"
);
inteveryPage=2;
inttotalCount=list.size();
inttotalPage=totalCount/everyPage+1;
StringpageNum=request.getParameter("
pageNum"
if(pageNum==null||pageNum.equals("
"
)){
currentPage=1;
}else{
currentPage=Integer.parseInt(pageNum);
if(currentPage<
=0){
currentPage=1;
}elseif(currentPage>
totalPage){
currentPage=totalPage;
}
}
if(currentPage>
0&
currentPage<
=totalPage){
firstCount=(currentPage-1)*everyPage+1;
=(totalPage-1)){
endCount=firstCount+everyPage;
}elseif((currentPage)>
(currentPage==totalPage)){
endCount=firstCount+totalCount%everyPage;
%>
<
485"
1"
align="
<
<
tdalign="
id
商品名称
商品数量
for(inti=firstCount;
i<
endCount;
i++){
%>
<
%=((MyPackage.Product)list.get(i-1)).getId()%>
%=((MyPackage.Product)list.get(i-1)).getName()%>
%=((MyPackage.Product)list.get(i-1)).getNum()%>
}
%>
%=basePath%>
Result.jsp?
pageNum=<
%=currentPage-1%>
上一页<
%=currentPage+1%>
下一页<
/Main.jsp"
gobacktomainpage<
2、Servlet源代码
1)AddServlet代码:
(仅列出关键部分)
//关键变量:
Stringid=newString();
Stringname=newString();
intnum;
Stringa=newString();
Stringsql1=newString();
Stringsql2=newString();
Connectionconn=null;
Statementstmt=null;
ResultSetrs=null;
PreparedStatementps=null;
//关键函数
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException
{
id=request.getParameter("
name=request.getParameter("
a=request.getParameter("
if(a==null||a.equals("
))
{
num=0;
}
elsenum=Integer.parseInt(a);
if(id!
=null&
!
id.equals("
Add(request,response,id,name,num);
}
else
ShowAll(request,res