JSTL+EL与商品管理+分页显示

来源:互联网 发布:微信里的淘宝链接 编辑:程序博客网 时间:2024/05/18 14:46

主要内容:

1 JSTL知识点 2 EL知识点 3 商品的管理(增删改查――图片的上传、删除与更换) 4 分页管理

详细内容:
1 JSTL知识点
JSP 标准标记库(Standard Tag Library,JSTL)是一组以标准化格式实现许多通用的Web站点功能的定制标记。JSTL的目标是为了简化JSP 页面的设计。

(1).配置JSTL

包括两个JAR文件,jstl.jar和standard.jar。
原文引入:
<%@taglibprefix=”c”uri=”http://java.sun.com/jsp/jstl/core”%>
<%@taglibprefix=”sql”uri=”http://java.sun.com/jsp/jstl/sql”%>
<%@taglibprefix=”fmt”uri=”http://java.sun.com/jsp/jstl/fmt”%>

(2).core标签库

Core标签库主要包括了一般用途的标签、条件标签、迭代标签和URL相关的标签。在JSP页面使用Core标签,要使用taglig指令,指定引用的标签库,如下: <%@tagliburi=”http://java.sun.com/jsp/jstl/core”prefix=”c”%> 一般用途的标签有、、、 用于计算一个表达式并将结果输出。类似于JSP中<%=%>表达式,或者是EL中elexpression<c:set>javabean<c:setvar=usernamevalue=lisiscope=session/>session<c:remove><c:set><c:removevar=nusernamescope=session/><c:catch>:<c:catch>:</c:catch>varpagevarvarEg<c:catchvar=exception><{exception}”/>

(1)实体类Page类(cn.sdut.po.page.java):

package cn.sdut.po;public class Page { private int totalPage; // 总页数 private int currentPage; // 当前页数 private int pageSize; // 每页记录条数 private int totalCount; // 总记录数 private int beginIndex; // 查询起始点,第1条为0 // mysql数据库 limit beginIndex,size public Page(int currentpage,int pageSize,int totalCount) {  this.currentPage=currentpage;  this.pageSize=pageSize;  this.totalCount=totalCount;  calBeginIndex();  //计算开始的记录索引位置  calTotalPage();   //计算总页数 } //计算开始的记录索引位置 void calBeginIndex() {  this.beginIndex=(currentPage-1)*pageSize; } //计算总页数 void calTotalPage() {  if(totalCount%pageSize==0)  {   totalPage=totalCount/pageSize;  }  else  {   totalPage=totalCount/pageSize+1;  } } public int getTotalPage() {  return totalPage; } public int getCurrentPage() {  return currentPage; } public int getPageSize() {  return pageSize; } public int getTotalCount() {  return totalCount; } public int getBeginIndex() {  return beginIndex; } }

(2)DAO层:

DBUtilsBaseDao.java(支持JAR包:commons-dbutils-1.6.jar mysql-connector-java-5.1.18-bin.jar)

DBUtilsBaseDao.java

package cn.sdut.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.util.List;import org.apache.commons.dbutils.DbUtils;import org.apache.commons.dbutils.QueryRunner;import org.apache.commons.dbutils.handlers.BeanListHandler;public class DBUtilsBaseDao {         //得到数据库连接         public  Connection getConn()         {                   Connection conn=null;                   DbUtils.loadDriver("com.mysql.jdbc.Driver");                   try {                            conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/shopping?useUnicode=true&characterEncoding=utf-8","root","usbw");                   } catch (SQLException e) {                            // TODO Auto-generated catch block                            e.printStackTrace();                   }                   return conn;         }         //增、删、改数据库的方法         public int update(String sql,Object... param)         {                   int result=0;                   Connection conn=getConn(); //得到连接                   QueryRunner runner=new QueryRunner();  //得到运行对象                   try {                            result=runner.update(conn, sql, param); //进行数据库操作                   } catch (SQLException e) {                            e.printStackTrace();                   }                   finally                   {                            DbUtils.closeQuietly(conn);  //关闭数据库连接                   }                   return result;         }         //数据库查询         public List query(String sql,Class clazz,Object... param)         {                   List list=null;                   Connection conn=getConn(); //得到连接                   QueryRunner runner=new QueryRunner();  //得到运行对象                   try {                            list=runner.query(conn,sql,new BeanListHandler(clazz),param); //进行数据库操作                   } catch (SQLException e) {                            e.printStackTrace();                   }                   finally                   {                            DbUtils.closeQuietly(conn);  //关闭数据库连接                   }                   return list;         }          //批量操作数据库的方法                   public boolean bactchUpdate(String sql,Object[][] param)                   {                            int[] result=new int[param.length];                            int r=1;                                                   Connection conn=getConn(); //得到连接                                                     QueryRunner runner=new QueryRunner();  //得到运行对象                            try {                                     result=runner.batch(conn,sql,param);// 批量进行数据库操作                            } catch (SQLException e) {                                     e.printStackTrace();                            }                            finally                            {                                     DbUtils.closeQuietly(conn);  //关闭数据库连接                            }                            //对返回数据进行加工,将整型数组转化为布尔类型                            for(int i=0;i<result.length;i++)                            {                                     r*=result[i];                            }                            return r>0?true:false;                   }}

cn.sdut.dao.ProductDao.java:

package cn.sdut.dao;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import cn.sdut.po.Product;public class ProductDao extends DBUtilsBaseDao {         // 显示所有商品         public List<Product> queryAllProducts() {                   String sql = "select * from product";                   List<Product> productList = query(sql, Product.class, null);                   return productList;         }         // 根据浏览记录获得商品列表         public List<Product> queryProducts(String historyList) {                   String[] productIds = historyList.split(",");                   List<Product> productList = new ArrayList<Product>();                   int len = productIds.length;                   for (int i = 0; i < len; i++) {                            productList.add(queryProductById(Integer.parseInt(productIds[i])));                   }                   return productList;         }         // 根据主键查询商品         public Product queryProductById(int id) {                   Product product = null;                   String sql = "select * from product where proid=?";                   List<Product> products = query(sql, Product.class, id);                   if (products != null && products.size() > 0) {                            product = products.get(0);                   }                   return product;         }         //增加商品         public int addProduct(Product product)         {                   int result=0;                   String sql="insert into product(proname,proprice,procount,prosupplier,propic) values(?,?,?,?,?)";                   Object[] param=new Object[]{                                     product.getProname(),                                     product.getProprice(),                                     product.getProcount(),                                     product.getProsupplier(),                                     product.getPropic()                   };                   result=update(sql, param);                   return result;         }         //根据主键删除商品         public int delProduct(int id)         {                   int result=0;                   String sql="delete from product where proid=?";                              result=update(sql, id);                   return result;         }         //修改商品         public int updateProduct(Product product)         {                   int result=0;                   String sql="update product set proname=?,proprice=?,procount=?,prosupplier=?,propic=? where proid=?";                   Object[] param=new Object[]{                                     product.getProname(),                                     product.getProprice(),                                     product.getProcount(),                                     product.getProsupplier(),                                     product.getPropic(),                                     product.getProid()                   };                   result=update(sql, param);                   return result;         }         //批量删除商品         public boolean batchDelProduct(int[] ids)         {                   boolean result=false;                   String sql="delete from product where proid=?";                   Object[][] params=new Object[ids.length][1];                   for(int i=0;i<ids.length;i++)                   {                            params[i][0]=ids[i];                   }                   result=bactchUpdate(sql, params);                   return result;         }         //分页查询数据         public List<Product> queryProductByPage(int beginIndex,int pageSize)         {                   String sql="select * from product limit ?,?";                   return query(sql, Product.class, new Object[]{beginIndex,pageSize});         }}

(3)控制层ProductServlet

package cn.sdut.servlet;import java.io.File;import java.io.IOException;import java.util.Iterator;import java.util.List;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.fileupload.FileItem;import org.apache.commons.fileupload.FileItemFactory;import org.apache.commons.fileupload.FileUploadException;import org.apache.commons.fileupload.disk.DiskFileItemFactory;import org.apache.commons.fileupload.servlet.ServletFileUpload;import cn.sdut.dao.ProductDao;import cn.sdut.po.Page;import cn.sdut.po.Product;/** * Servlet implementation class ProductServlet */@WebServlet("/ProductServlet")public class ProductServlet extends HttpServlet {         private static final long serialVersionUID = 1L;         ProductDao productDao = new ProductDao();         public ProductServlet() {                   super();         }         protected void doGet(HttpServletRequest request,                            HttpServletResponse response) throws ServletException, IOException {                   request.setCharacterEncoding("utf-8");                   response.setCharacterEncoding("utf-8");                   String method = request.getParameter("method");                   switch (method) {                   case "all":                            queryAllProduct(request, response);                            break;                   case "add":                            addProduct(request, response);                            break;                   case "del":                            delProduct(request, response);                            break;                   case "update":                            updateProduct(request, response);                            break;                   case "byid":                            queryProductById(request, response);                            break;                   case "batchDel":                            batchDelProduct(request, response);                            break;                   case "byPage":                            queryProductByPage(request,response);                            break;                   }         }         private void queryProductByPage(HttpServletRequest request,                            HttpServletResponse response) throws ServletException, IOException {                   //得到当前页数                   String currPage=request.getParameter("currentPage");                   int currentPage=1;                   if(currPage!=null)                   {                            System.out.println(currPage);                            currentPage=Integer.parseInt(currPage);                   }                   //得到总记录数量                   int totalCount=0;                   List<Product> products=productDao.queryAllProducts();                   if(products!=null)                   {                            totalCount=products.size();                   }                   //页面大小——每页显示几条记录                   int pageSize=5;                   //创建页处理对象                   Page page=new Page(currentPage,pageSize,totalCount);                   //得到当前页显示的记录索引(从0开始)                   int beginIndex=page.getBeginIndex();                  //得到当前页的商品列表                   List<Product> productByPage = productDao.queryProductByPage(beginIndex, pageSize);                   //将商品信息和页对象放入request作用域,供页面展示使用                   request.setAttribute("productList", productByPage);                   request.setAttribute("page", page);                   //转向页面                   request.getRequestDispatcher("/product/m_productMain.jsp").forward(request, response);         }         private void queryAllProduct(HttpServletRequest request,                            HttpServletResponse response) throws ServletException, IOException {                   List<Product> products = productDao.queryAllProducts();                   request.setAttribute("productList", products);                   request.getRequestDispatcher("/product/m_productMain.jsp").forward(request, response);         }         // 增加商品(涉及上传图片文件)         private void addProduct(HttpServletRequest request,                            HttpServletResponse response) throws IOException {                   boolean isMultipart = ServletFileUpload.isMultipartContent(request);                   // 判断是带文件上传的表单?还是普通表单                   boolean isuploadSuccess = false; // 设置上传成功的标志                   File imageFile = null; // 图片文件对象                   String proname = null; // 商品名称                   String pronumber = null; // 商品数量                   String proprice = null; // 商品价格                   String prosupplier = null; // 商品供应商                   String propic = null; // 商品的图片文件名                   String destFileName = null; // 重新组织的商品文件名                   try {                            String uploaddir = request.getServletContext().getRealPath(                                               "/images");                            // 设置上传路径字符串                            File upFile = new File(uploaddir); // 创建路径对应的文件对象                            if (!upFile.exists()) { // 如果路径不存在,就逐级创建                                     upFile.mkdirs();                            }                            if (isMultipart == true) { // 若是带文件上传的表单,继续                                     FileItemFactory factory = new DiskFileItemFactory(); // 创建文件项工厂                                     ServletFileUpload upload = new ServletFileUpload(factory); // 创建文件上传对象                                     List<FileItem> items; // 表单项列表                                     items = upload.parseRequest(request); // 解析请求对象,得到各个表单项                                     // 对表单里的各个项目进行分析:                                     // 如果是普通文本框,则取得其字段名称,根据名称获得其值                                     // 如果是文件上传项,则取得文件名,对文件名进行处理,然后上传                                     Iterator<FileItem> it = items.iterator();                                     while (it.hasNext()) { // 单文件上传                                               FileItem item = (FileItem) it.next();                                               // 处理普通文本                                               String fileldName = item.getFieldName(); // 得到域名称                                               switch (fileldName) // 根据名称取得其数据,由二进制数据转换成UTF-8编码                                               {                                               case "proname":                                                        proname = new String(item.getString().getBytes(                                                                           "iso-8859-1"), "utf-8");                                                        break;                                               case "proprice":                                                        proprice = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               case "pronumber":                                                        pronumber = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               case "prosupplier":                                                        prosupplier = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               }                                               // 处理文件上传数据                                               if (!item.isFormField()) { // 文件,不包含普通表单内容                                                        propic = item.getName(); // 得到文件名称                                                        // 根据当前时间的毫秒数+原文件的扩展名来构造目标图片文件名称                                                        long t = System.currentTimeMillis(); // 得到系统当前毫秒数                                                        destFileName = t                                                                           + propic.substring(propic.lastIndexOf("."));                                                        imageFile = new File(uploaddir, destFileName); // 目标文件对象                                                        try {                                                                 item.write(imageFile); // 实际写图片文件                                                                 isuploadSuccess = true; // 设置文件上传成功的标志                                                        } catch (Exception e) {                                                                 e.printStackTrace();                                                                 isuploadSuccess = false;                                                                 System.out.println("上传失败!!");                                                        }                                               } else {                                                        // 普通表单内容 不处理                                                        System.out.println(item.toString());                                               }                                     }                            } else {                                     System.out.print("the enctype must be multipart/form-data");                            }                   } catch (FileUploadException e) {                            e.printStackTrace();                   }                   //组织数据向数据库写入                   double price = Double.parseDouble(proprice); // 将商品价格转化成数值                   int count = Integer.parseInt(pronumber); // 将商品数量转化成数值                   Product product = new Product(0, proname, price, count, prosupplier,destFileName);                   int result=productDao.addProduct(product);                   String msg = result > 0 ? "商品插入成功" : "商品插入不成功";                   request.setAttribute("msg", msg);                   //转向页面显示数据                   response.sendRedirect(request.getContextPath()+"/ProductServlet?method=byPage");         }         private void delProduct(HttpServletRequest request,                            HttpServletResponse response) throws ServletException, IOException {                   int proid = Integer.parseInt(request.getParameter("proid"));                   //1 在数据库进行删除记录                   int result = productDao.delProduct(proid);                   String msg = result > 0 ? "删除商品成功" : "删除商品不成功";                   //2 删除商品对应的图片文件                   String path=getServletContext().getRealPath("/images"); //得到图片路径                   Product product=productDao.queryProductById(proid); //得到商品对象                   String propic = product.getPropic();//得到图片文件名称                   File file=new File(path,propic);    //构建图片文件对象                   if(file.exists())  //若文件存在,就删除                   {                            file.delete();                   }                   //转向页面显示数据                   request.setAttribute("msg", msg);                   request.getRequestDispatcher("/ProductServlet?method=byPage").forward(request, response);         }         private void updateProduct(HttpServletRequest request,                            HttpServletResponse response) throws IOException {                   boolean isMultipart = ServletFileUpload.isMultipartContent(request);                   // 判断是带文件上传的表单?还是普通表单                   boolean isuploadSuccess = false; // 设置上传成功的标志                   File imageFile = null; // 图片文件对象                   String proid=null;                   String proname = null; // 商品名称                   String pronumber = null; // 商品数量                   String proprice = null; // 商品价格                   String prosupplier = null; // 商品供应商                   String propic = null; // 商品的图片文件名                   String destFileName = null; // 重新组织的商品文件名                   String uploaddir=null;                   try {                             uploaddir = request.getServletContext().getRealPath("/images");                            // 设置上传路径字符串                            File upFile = new File(uploaddir); // 创建路径对应的文件对象                            if (!upFile.exists()) { // 如果路径不存在,就逐级创建                                     upFile.mkdirs();                            }                            if (isMultipart == true) { // 若是带文件上传的表单,继续                                     FileItemFactory factory = new DiskFileItemFactory(); // 创建文件项工厂                                     ServletFileUpload upload = new ServletFileUpload(factory); // 创建文件上传对象                                     List<FileItem> items; // 表单项列表                                     items = upload.parseRequest(request); // 解析请求对象,得到各个表单项                                     // 对表单里的各个项目进行分析:                                     // 如果是普通文本框,则取得其字段名称,根据名称获得其值                                     // 如果是文件上传项,则取得文件名,对文件名进行处理,然后上传                                     Iterator<FileItem> it = items.iterator();                                     while (it.hasNext()) { // 单文件上传                                               FileItem item = (FileItem) it.next();                                               // 处理普通文本                                               String fieldName = item.getFieldName(); // 得到域名称                                               System.out.println(fieldName+"==");                                               switch (fieldName) // 根据名称取得其数据,由二进制数据转换成UTF-8编码                                               {                                               case "proid":                                                        proid = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               case "proname":                                                        proname = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               case "proprice":                                                        proprice = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               case "pronumber":                                                        pronumber = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               case "prosupplier":                                                        prosupplier = new String(item.getString().getBytes("iso-8859-1"), "utf-8");                                                        break;                                               }                                               // 处理文件上传数据                                               if (!item.isFormField()) { // 文件,不包含普通表单内容                                                        propic = item.getName(); // 得到文件名称                                                        // 根据当前时间+原文件的扩展名来构造目标图片文件名称                                                        long t = System.currentTimeMillis(); // 得到系统当前毫秒数                                                        destFileName = t                                                                           + propic.substring(propic.lastIndexOf("."));                                                        imageFile = new File(uploaddir, destFileName); // 目标文件对象                                                        try {                                                                 item.write(imageFile); // 实际写图片文件                                                                 isuploadSuccess = true; // 设置文件上传成功的标志                                                        } catch (Exception e) {                                                                 e.printStackTrace();                                                                 isuploadSuccess = false;                                                                 System.out.println("上传失败!!");                                                        }                                               } else {                                                        // 普通表单内容 不处理                                                        System.out.println("--"+item.toString());                                               }                                     }                            } else {                                     System.out.print("the enctype must be multipart/form-data");                            }                   } catch (FileUploadException e) {                            e.printStackTrace();                   }                   //处理数据库数据,并将服务器中的原来图片删除                   int id=Integer.parseInt(proid);//得到商品ID                   Product productOld=productDao.queryProductById(id); //根据主键得到商品信息                   String propicOld=productOld.getPropic(); //得到数据库中原来图片名称                   File file=new File(uploaddir,propicOld); //构建图片文件对象                   if(file.exists())  //若文件对象存在,就删除                   {                            file.delete();                   }                   double price = Double.parseDouble(proprice); // 将商品价格转化成数值                   int count = Integer.parseInt(pronumber); // 将商品数量转化成数值                   Product product = new Product(id, proname, price, count, prosupplier,                                     destFileName);                   productDao.updateProduct(product);   //修改商品信息                   response.sendRedirect(request.getContextPath()                                     + "/ProductServlet?method=byPage");         }         private void queryProductById(HttpServletRequest request,                            HttpServletResponse response) throws ServletException, IOException {                   int proid = Integer.parseInt(request.getParameter("proid"));                   Product product = productDao.queryProductById(proid);                   request.setAttribute("product", product);                   request.getRequestDispatcher("/product/m_updateProduct.jsp").forward(                                     request, response);         }//批量删除商品的同时,删除图片         private void batchDelProduct(HttpServletRequest request,                            HttpServletResponse response) throws ServletException, IOException {                   String path = getServletContext().getRealPath("/images");                   // 在数据库中删除商品信息                   String[] proids = request.getParameterValues("proid");                   if (proids != null && proids.length > 0) {                            int[] ids = new int[proids.length];                            for (int i = 0; i < proids.length; i++) {                                     ids[i] = Integer.parseInt(proids[i]);                                     // 删除图片                                     Product product = productDao.queryProductById(ids[i]);                                     String pic = product.getPropic();                                     File file = new File(path, pic);                                     if (file.exists()) {                                               file.delete();                                     }                            }                            boolean result = productDao.batchDelProduct(ids);                            String msg = result ? "批量删除商品成功" : "批量删除商品不成功";                            request.setAttribute("msg", msg);                   }                   request.getRequestDispatcher("/ProductServlet?method=byPage").forward(request, response);         }         protected void doPost(HttpServletRequest request,                            HttpServletResponse response) throws ServletException, IOException {                   doGet(request, response);         }}

(4)VIEW层——JSP页面

m_productMain.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">    <title>My JSP ’m_main.jsp’ starting page</title>         <meta http-equiv="pragma" content="no-cache">         <meta http-equiv="cache-control" content="no-cache">         <meta http-equiv="expires" content="0">            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">         <meta http-equiv="description" content="This is my page">         <!--         <link rel="stylesheet" type="text/css" href="styles.css">         -->         <script type="text/javascript">           function batchDelete()           {              form1.action="<%=path%>/ProductServlet?method=batchDel";              form1.submit();           }         </script>  </head>  <body>  <br>  <table width="710" height="169" border="1" align="center">  </table>  <form name="form1" method="post" action="">    <table width="710" height="169" border="1" align="center">      <caption>        <h3>商品管理</h3>      </caption>      <tr>        <td width="65" align="center">选择</td>        <td width="50" align="center">序号</td>        <td width="158" align="center">商品名称</td>        <td width="85" align="center">图片</td>        <td width="70" align="center">产地</td>        <td width="67" align="center">库存数量</td>        <td width="64" align="center">价格</td>        <td width="99" align="center">操作</td>      </tr>      <c:forEach items="${productList}" var="product" varStatus="status">      <tr>        <td height="42" align="center"><input type="checkbox" name="proid" id="proid" value="${product.proid}"></td>        <td align="center">${status.count}</td>        <td>${product.proname }</td>        <td><img src="images/${product.propic}" width="100" height="75"></td>        <td>${product.prosupplier }</td>        <td>${product.proprice }</td>        <td>${product.procount }</td>        <td>&nbsp;                 <a href="ProductServlet?method=byid&proid=${product.proid}">修改</a>                   <a href="ProductServlet?method=del&proid=${product.proid}">删除</a>         </td>      </tr>      </c:forEach>      <tr>        <td height="43" colspan="8" align="center">          <br>         <input type="button" name="addProduct" id="addProduct" value="增加商品"onclick="javascript:window.location.href=’<%=path%>/product/m_addProduct.jsp’">          &nbsp; &nbsp;          <input type="button" name="batchDel" id="batchDel" value="批量删除" onclick="batchDelete()">             <br>  <br>             总${page.totalPage}页,第${page.currentPage}页   &nbsp; &nbsp;&nbsp; &nbsp;             <a href="<%=path%>/ProductServlet?method=byPage&currentPage=1">首页 </a>             <c:if test="${page.currentPage>1}">                <a href="<%=path%>/ProductServlet?method=byPage&currentPage=${page.currentPage-1}">上一页 </a>             </c:if>             <c:if test="${page.currentPage<=1}">                  上一页             </c:if>             <c:if test="${page.currentPage<page.totalPage}">               <a href="<%=path%>/ProductServlet?method=byPage&currentPage=${page.currentPage+1}">下一页</a>             </c:if>             <c:if test="${page.currentPage>=page.totalPage}">                  下一页             </c:if>             <a href="<%=path%>/ProductServlet?method=byPage&currentPage=${page.totalPage}">尾页</a>          &nbsp;&nbsp;&nbsp;           <!-- 下拉框中显示页数 实现页的选择   -->                        <select onchange="window.location.href=’<%=path%>/ProductServlet?method=byPage&currentPage=’+this.value" >                  <c:forEach begin="1" end="${page.totalPage}" var="index">                         <option value="${index}" > ${index}</option>                  </c:forEach>              </select>    <br> <br>     </td> </tr>       </table>   &nbsp; &nbsp; &nbsp; &nbsp;  ${msg }    <p>&nbsp;</p>  </form>  </body></html>

m_addProduct.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">    <title>My JSP ’m_addOrUpdate.jsp’ starting page</title>         <meta http-equiv="pragma" content="no-cache">         <meta http-equiv="cache-control" content="no-cache">         <meta http-equiv="expires" content="0">            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">         <meta http-equiv="description" content="This is my page">         <!--         <link rel="stylesheet" type="text/css" href="styles.css">         -->  </head>  <body>  <br>  <form name="form1" method="post" action="<%=path%>/ProductServlet?method=add" enctype="multipart/form-data">    <table width="500" height="290" border="1">    <caption><h3>商品增加</h3></caption>      <tr>        <td width="190" align="center">商品名称:</td>        <td width="294"><input type="text" name="proname" id="proname"></td>      </tr>      <tr>        <td align="center">商品价格:</td>        <td><input type="text" name="proprice" id="proprice"></td>      </tr>      <tr>        <td align="center"><p>库存数量:</p></td>        <td><input type="text" name="pronumber" id="pronumber"></td>      </tr>      <tr>        <td align="center">生产商:</td>        <td><input type="text" name="prosupplier" id="prosupplier"></td>      </tr>      <tr>        <td align="center">图片:</td>        <td><input type="file" name="propic" id="propic"></td>      </tr>      <tr>        <td colspan="2" align="center">        <input type="submit" name="submit" id="submit" value="提交">          &nbsp; &nbsp;          <input type="reset" name="reset" id="reset" value="重置"></td>      </tr>    </table>  </form>  </body></html> ```##m_updateProduct.jsp
0 0
原创粉丝点击