一:带模糊查询功能的分页功能显示:
①:引入JSTL标签库的基本驱动包
②:用taglib引入JSTL标签库
?
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>?
③:设置好带具有模糊查询功能的主界面
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>红旗牌购物商场</title>
</head>
<body><form action="doIndex.jsp" method="post"><input name="key" value="${ key }"> <button>搜索</button></form><hr><table border><tr><td>商品序号</td><td>商品名称</td><td>商品价格</td><td>操作</td></tr><c:forEach items="${ gls }" var="g"><tr><td>${ g.gid }</td><td>${ g.gname }</td><td>${ g.gprice }</td><td><a>删除</a><a href="perUpdate.jsp?gid=${ g.gid }">修改</a></td></tr></c:forEach> </table><a href="doIndex.jsp?pid=${ pageSize-1<1?1:pageSize-1 }&key=${ key}">上一页</a>【${ pageSize }/${ max }】<a href="doIndex.jsp?pid=${ pageSize+1>max?max:pageSize+1 }&key=${ key}">下一页</a>
</body>
</html>
④:为了使jsp页面不含有java代码,所以特别设置一个首页数据显示的预处理do页面
?
<%@page import="com.entity.Goods"%>
<%@page import="java.util.List"%>
<%@page import="com.biz.impl.GoodsBiz"%>
<%@page import="com.biz.IGoodsBiz"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%//就是处理index所需要的数据的int pageSize=1;//当前页数int rows=2;//每页显示几个int max=0;//最大页数//接收的页数String pid=request.getParameter("pid"); //"3"if(pid!=null){pageSize=Integer.parseInt(pid);}//接收关键字String key=request.getParameter("key");if(key==null){key="";//查询全部}IGoodsBiz igb=new GoodsBiz();List<Goods> list=igb.getAll(pageSize, rows,key);//计算页数max=igb.getRows(key)/rows;if(igb.getRows(key)%rows!=0){max++;}if(max==0)max=1;//如何将数据发送到index.jsp界面//pageContext request session application//应该是将数据给到requestrequest.setAttribute("gls", list);request.setAttribute("pageSize", pageSize);request.setAttribute("max", max);request.setAttribute("key", key);//请求的数据只会在转发的时候才会有效request.getRequestDispatcher("index.jsp").forward(request, response);
%>?
购物车后台的商品修改功能
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>商品信息修改</title></head><body><form>商品标号 <input readonly value="${ g.gid }"><br>商品名称 <input value="${ g.gname }"><br>商品价格 <input value="${ g.gprice }"><br><button>确认修改</button></form></body>
</html>
do处理界面----负责处理商品信息修改界面传来
<%@page import="com.entity.Goods"%>
<%@page import="com.biz.impl.GoodsBiz"%>
<%@page import="com.biz.IGoodsBiz"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%//接收到需要查询的gidString gid=request.getParameter("gid");//查询对应的商品信息IGoodsBiz igb=new GoodsBiz();Goods g=igb.getById(Integer.parseInt(gid));//将数据发送到修改界面request.setAttribute("g", g);request.getRequestDispatcher("upd.jsp").forward(request, response);%>