..................................................
3)代码:
..................................................
..................................................
4)代码:
..................................................
..................................................
5)代码:
..................................................
..................................................
6)代码:
..................................................
<%
intcurrentPage=1;
intfirstCount=1;
intendCount=1;
Listlist=null;
list=(ArrayList)("list");
inteveryPage=2;
inttotalCount=();
inttotalPage=totalCount/everyPage+1;
+totalPage);
+totalCount);
StringpageNum=("pageNum");
if(pageNum==null||("")){
currentPage=1;
}else{
currentPage=(pageNum);
if(currentPage<=0){
currentPage=1;
}elseif(currentPage>totalPage){
currentPage=totalPage;
}
}
if(currentPage>0&¤tPage<=totalPage){
firstCount=(currentPage-1)*everyPage+1;
}
+currentPage);
+firstCount);
if(currentPage>0&¤tPage<=(totalPage-1)){
endCount=firstCount+everyPage;
}elseif((currentPage)>0&&(currentPage==totalPage)){
endCount=firstCount+totalCount%everyPage;
}
+endCount);
%>
id
商品名称
商品数量
<%
for(inti=firstCount;i %> <%=((i-1)).getId()%> <%=((i-1)).getName()%> <%=((i-1)).getNum()%> <% } %>
pageNum=<%=currentPage-1%>">上一页
pageNum=<%=currentPage+1%>">下一页
..................................................
2、Servlet源代码
1)AddServlet代码:
(仅列出关键部分)
..................................................
orward(request,response);
}
catch(SQLExceptione)
{
}
}
publicvoidShowAll(HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException,ServletException
{
ArrayListl=newArrayList();
try
{
}
catch(Exceptione)
{
}
try
{
stmt=();
Stringsql=newString("select*fromshangpin");
rs=(sql);
l=(ArrayList)MakeList(rs);
HttpSessions=();
("list",l);
("/").forward(request,response);
}
catch(SQLExceptione)
{
}
}
publicList
{
List
while())
{
Productp=newProduct
(1),
(2),(3));
(p);
}
returnl;
}
publicvoidinit()throwsServletException{
}
}
..................................................
2)QueryServlet代码:
..................................................
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
id=("id");
name=("name");
a=("num");
if(a==null||(""))
{
num=0;
}
elsenum=(a);
if(id!
=null&&!
(""))
{
QueryById(request,response,id);
}
elseif(name!
=null&&!
(""))
{
QueryByName(request,response,name);
}
elseif(num!
=0)
{
QueryByNum(request,response,num);
}
else
ShowAll(request,response);
}
publicvoidQueryById(HttpServletRequestrequest,HttpServletResponseresponse,Stringid)
{
ArrayListl=newArrayList();
try
{
conn=
}
catch(Exceptione)
{
"Openconn:
"+());
}
try
{
stmt=();
Stringsql=newString("select*fromshangpinwhereid="+"'"+id+"'");
rs=(sql);
l=(ArrayList)MakeList(rs);
Http
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2