目录

  • 1、题目说明
  • 2、实验设计
    • 2.1 表设计
    • 2.2 工程结构
  • 3、运行界面截图与说明
  • 4、小结
  • 附录:源代码
    • src/main/java
      • src/main/java/bean
        • Goods.java
        • PageBean.java
      • src/main/java/dao
        • GoodsDao.java
        • src/main/java/dao/impl
          • GoodsDaoImpl.java
      • src/main/java/db
        • DBConn.java
      • src/main/java/service
        • GoodsService.java
        • src/main/java/service/impl
          • GoodsServiceImpl.java
      • src/main/java/servlet
        • AddServlet.java
        • DeleteServlet.java
        • GoodsListPageServlet.java
        • GoodsListServlet.java
        • SearchGoodsServlet.java
      • src/main/java/util
        • JDBCUtil.java
        • TextUtil.java
    • src/main/webapp
      • src/main/webapp/WEB-INF
        • web.xml
      • add.jsp
      • head.jsp
      • list.jsp
      • list_page.jsp
      • main.jsp
      • style.css

1、题目说明

1、采用MVC模式实现商品信息的查询显示(可以模糊查询)、增加和删除功能,商品表自拟;
2、实现简单菜单操作和分页显示(每页显示20条)
3、选做:商品包括图片
要求:
1、可以使用基本的web开发技术,也可以使用框架
2、报告模板见附件,工程打包作为附件上传

2、实验设计

2.1 表设计



在数据库中,设计了一个商品表。在商品表中,使用了三个字段:id,表示商品的id编号,是主键且不能重复。gname,表示商品名称,添加了unique约束,也不能重复。Price,表示商品价格,类型为decimal数值,能有2位小数。

2.2 工程结构


整个工程使用的mvc模式,类模型model、用户视图前端view、后端控制controller分离。
在图3的webapp结构中,webapp用于显示前端与对后端发送请求。lib文件夹为本工程导入的外部jar包,包括apache服务器自带的数据库工具等。add.jsp页面实现添加商品的功能,head.jsp页面为网页顶部的简单的菜单项功能。list_page.jsp实现分页显示商品列表功能。list.jsp实现了商品的查询功能,支持模糊查询。logo.jpg为校徽,实现了简单的图片显示功能。main.jsp为首页,在启动时运行main.jsp。style.css为菜单功能实现时所需的前端样式。web.xml配置了servlet。

在图4的后端的工程结构中,可以看到除webapp外的其他文件结构。
bean包存放了类模型。Goods.java是商品的类型,含有属性、getter/setter方法,并自带构造函数。因为要实现一个分页显示的功能,所以引入了PageBean文件,含有属性、getter/setter等方法与构造函数。PageBean还是一个模板类,在本工程中,该模板类的参数就是Goods。
在工程中,其余的包用于对后端进行控制。
Dao包存放的是数据库访问对象。GoodsDao.java是接口,GoodsDaoImpl.Java是对GoodsDao接口的实现类。在GoodsDaoImpl中,调用了JDBCUtil,并使用apahce服务器提供的用于操纵数据库的相关库。使用了连接池的技术。GoodsDao用于访问数据库,所有服务service功能都会调用GoodsDao中的相关函数与方法对数据库进行操作,对数据库进行增、删、查等多种操作。
DBConn是数据库连接对象。
service包用于存放服务。GoodsService.java是接口,GoodsServiceImpl.java是GoodsService接口的实现类。在GoodsServiceImpl中,对于servlet所调用的的增、删、查功能,service负责调用GoodsDao对数据库进行操作。
servlet包用于存放前端的jsp文件所请求的servlet,接受并解析请求。并调用service包中的相关函数进行增、删、查。在对数据库进行增、删、查完毕后,servlet还负责将前端页面进行重定位。AddServlet用于处理添加商品请求,DeleteServlet用于删除请求,GoodsListServlet用于直接显示所有商品请求,GoodsListPageSerlet用于分页查询请求,SearchGoodsServlet用于模糊查询请求。
util包存放的是工具类。TextUtil是文本工具,用于判断文本是否为空。JDBCUtil是JDBC数据库连接工具,调用apache服务器的连接池。同时,需要修改本地apache服务器的相关配置。

3、运行界面截图与说明


点击”main.jsp”进入首页,首页实现了简单的菜单功能并显示了图片,图片为校徽。在菜单功能中,有两个选项,分别为“增加商品”和“显示商品”。当鼠标悬停在菜单某一位置时,该项底色变为灰色,字颜色变为红色。


在这一页面中也可以添加商品,添加商品,商品名“iPadPro 256”,价格18888.00。在稍后对“显示商品”的演示时,我们可以看到这一项商品被正确地添加了。

点击“显示商品”,则商品会正确地显示出来。实现了分页显示的功能,每一页显示20条记录。

此为第二页。虽然每页显示20条记录,但本页只有3条记录。可以看到,之前添加的记录正确地被显示了出来。

实现了删除功能。点击“删除”,JavaScript会跳出提示询问用户“是否确定删除?”。

若用户确定删除,则商品能被正确地删除。

实现了商品信息的模糊查询功能。在“按名称查询”输入框输入“iphone”后,正确地找到了所有商品名称中带“iphone”的所有商品。

同样的,也可以按价格查询。正确地查到了价格为100.00的商品。

4、小结

附录:源代码

src/main/java

src/main/java/bean

Goods.java

package bean;public class Goods {private int id;private String gname;private double price;public int getId() {return id;}public String getName() {return gname;}public double price() {return price;}public void setId(int id) {this.id=id;}public void setName(String gname) {this.gname=gname;}public void setPrice(double price) {this.price=price;}public Goods() {}public Goods(String gname,double price) {this.gname=gname;this.price=price;}public Goods(int id,String gname,double price) {this.id=id;this.gname=gname;this.price=price;}public String toString() {return "Goods [id=" + id + ", gname=" + gname + ", price=" + price + "]";}
}

PageBean.java

package bean;
import java.util.List;
public class PageBean<T> {private int currentPage; //当前页private int totalPage;//总页数private int pageSize;//每页的记录数private int totalSize; //总的记录数private List<T> list; //当前页的学生集合public int getCurrentPage() {return currentPage;}public void setCurrentPage(int currentPage) {this.currentPage = currentPage;}public int getTotalPage() {return totalPage;}public void setTotalPage(int totalPage) {this.totalPage = totalPage;}public int getPageSize() {return pageSize;}public void setPageSize(int pageSize) {this.pageSize = pageSize;}public int getTotalSize() {return totalSize;}public void setTotalSize(int totalSize) {this.totalSize = totalSize;}public List<T> getList() {return list;}public void setList(List<T> list) {this.list = list;}
}

src/main/java/dao

GoodsDao.java

package dao;
import bean.Goods;
import java.sql.SQLException;
import java.util.List;/*** 这是针对商品表的数据访问 */
public interface GoodsDao {int PAGE_SIZE = 20; //一页显示多少条记录/*** 查询当页的商品数据*/List<Goods> findGoodsByPage(int currentPage) throws SQLException ;/*** 查询所有商品*/List<Goods> findAll()  throws SQLException ;/*** 根据ID查询单个商品对象*/Goods findGoodsById(int id)  throws SQLException ;List<Goods> searchGoods(String gname,double price)  throws SQLException ;void insert(Goods goods) throws SQLException ;void delete(int id) throws SQLException ;int findCount()throws SQLException ;}

src/main/java/dao/impl

GoodsDaoImpl.java
package dao.impl;
import dao.*;
import bean.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import util.*;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.apache.commons.dbutils.ResultSetHandler;
import db.DBConn;public class GoodsDaoImpl implements GoodsDao{public List<Goods> findAll()  throws SQLException{QueryRunner runner = new QueryRunner(JDBCUtil.getDataSource());return runner.query("select * from goods", new BeanListHandler<Goods>(Goods.class));}public List<Goods> findGoodsByPage(int currentPage) throws SQLException {QueryRunner runner = new QueryRunner(JDBCUtil.getDataSource());return runner.query("select * from goods limit 20 offset ?", new BeanListHandler<Goods>(Goods.class), (currentPage-1)*PAGE_SIZE);}public void delete(int id) throws SQLException {QueryRunner runner = new QueryRunner(JDBCUtil.getDataSource());runner.update("delete from goods where id=?" ,id);}public void insert(Goods goods) throws SQLException {QueryRunner runner = new QueryRunner(JDBCUtil.getDataSource());String sql="INSERT INTO `bigproject`.`goods`(`gname`, `price`) VALUES ('"+goods.getName()+"',"+ goods.getId()+")";runner.update(sql);}@Overridepublic int findCount() throws SQLException {QueryRunner runner = new QueryRunner(JDBCUtil.getDataSource());//用于处理 平均值 、 总的个数。 Long  result = (Long) runner.query("SELECT COUNT(*) FROM goods" , new ScalarHandler() );return result.intValue();}@Overridepublic List<Goods> searchGoods(String gname, double price) throws SQLException {System.out.println("现在要执行模糊查询了,收到的name=="+gname + "price"+price);QueryRunner runner = new QueryRunner(JDBCUtil.getDataSource());String sql = "select * from goods where 1=1 ";List<String> list = new ArrayList<String> ();//判断有没有名称, 如果有,就组拼到sql语句里面if(!TextUtil.isEmpty(gname)){sql = sql + "  and gname like ?";list.add("'%"+gname+"%'");}if(!TextUtil.isEmpty(String.valueOf(price))){sql = sql + " and price = ?";list.add(String.valueOf(price));}return runner.query(sql , new BeanListHandler<Goods>(Goods.class) ,list.toArray() );}public Goods findGoodsById(int id) throws SQLException {QueryRunner runner = new QueryRunner(JDBCUtil.getDataSource());return runner.query("select * from goods where sid = ?", new BeanHandler<Goods>(Goods.class) ,id);}public GoodsDaoImpl() {}}

src/main/java/db

DBConn.java

package db;
import java.sql.*;
public class DBConn {public Connection getConnection() {String URL = "jdbc:mysql://localhost:3306/bigproject?characterEncoding=utf-8";String USER = "root";String PASSWORD = "111111";try {Class.forName("com.mysql.cj.jdbc.Driver");Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);return conn;} catch (ClassNotFoundException e) {           e.printStackTrace();}catch (SQLException e) {           e.printStackTrace();}   return null;}
}

src/main/java/service

GoodsService.java

package service;import java.sql.SQLException;
import java.util.List;import bean.*;/*** 这是商品的业务处理规范**/
public interface GoodsService {PageBean findGoodsByPage(int currentPage) throws SQLException ;List<Goods> findAll()  throws SQLException ;/*** 根据ID查询单个商品对象*/Goods findGoodsById(int id)  throws SQLException ;/*** 模糊查询, 根据姓名或者根据性别,或者两者兼有。 */List<Goods> searchGoods(String gname , double price)  throws SQLException ;/*** 添加商品*/void insert(Goods goods) throws SQLException ;/*** 根据id删除商品*/void delete(int id) throws SQLException ;
}

src/main/java/service/impl

GoodsServiceImpl.java
package service.impl;import java.sql.SQLException;
import java.util.List;import dao.*;
import dao.impl.*;
import bean.*;
import service.*;
/*** 这是商品业务实现**/
public class GoodsServiceImpl implements GoodsService{@Overridepublic List<Goods> findAll() throws SQLException {GoodsDao dao = new GoodsDaoImpl();return dao.findAll();}@Overridepublic void insert(Goods goods) throws SQLException {GoodsDao dao = new GoodsDaoImpl();dao.insert(goods);}@Overridepublic void delete(int id) throws SQLException {GoodsDao dao = new GoodsDaoImpl();dao.delete(id);}@Overridepublic Goods findGoodsById(int id) throws SQLException {GoodsDao dao = new GoodsDaoImpl();return dao.findGoodsById(id);}@Overridepublic List<Goods> searchGoods(String gname, double price) throws SQLException {return new GoodsDaoImpl().searchGoods(gname, price);}@Overridepublic PageBean<Goods> findGoodsByPage(int currentPage) throws SQLException {//封装分页的该页数据PageBean<Goods> pageBean = new PageBean<Goods>();int pageSize = GoodsDao.PAGE_SIZE ;pageBean.setCurrentPage(currentPage); //设置当前页pageBean.setPageSize(pageSize); //设置每页显示多少记录GoodsDao dao = new GoodsDaoImpl() ;List<Goods> list =dao.findGoodsByPage(currentPage);pageBean.setList(list); //设置这一页的商品数据//总的记录数, 总的页数。int count = dao.findCount();pageBean.setTotalSize(count); //设置总的记录数//200 , 10 ==20   201 , 10 = 21   201 % 10 == 0 ?201 / 10 :201 % 10 + 1pageBean.setTotalPage(count % pageSize==0 ? count / pageSize : (count / pageSize) + 1); //总页数return pageBean;}}

src/main/java/servlet

AddServlet.java

package servlet;import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import bean.Goods;
import service.GoodsService;
import service.impl.GoodsServiceImpl;/*** 用于处理商品的添加请求**/
public class AddServlet extends HttpServlet {@Overridepublic void init() throws ServletException{super.init();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");try {//1. 获取客户端提交上来的数据String gname = request.getParameter("gname"); //sname:zhangsanString sprice = request.getParameter("price");double price=Double.parseDouble(sprice);Goods goods = new Goods(gname,price);GoodsService service = new GoodsServiceImpl();service.insert(goods);request.getRequestDispatcher("GoodsListServlet").forward(request, response);} catch (Exception e) {e.printStackTrace();}}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}}

DeleteServlet.java

package servlet;import java.io.IOException;
import java.sql.SQLException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import service.GoodsService;
import service.impl.GoodsServiceImpl;/*** 用于处理删除**/
public class DeleteServlet extends HttpServlet {@Overridepublic void init() throws ServletException{super.init();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {int id = Integer.parseInt(request.getParameter("id"));//2. 执行删除GoodsService service = new GoodsServiceImpl();service.delete(id);//3. 跳转到列表页。request.getRequestDispatcher("GoodsListServlet").forward(request, response);} catch (SQLException e) {e.printStackTrace();}}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}}

GoodsListPageServlet.java

package servlet;import java.io.IOException;
import java.sql.SQLException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.catalina.valves.StuckThreadDetectionValve;import bean.*;
import service.GoodsService;
import service.impl.GoodsServiceImpl;/*** 这是用于分页显示商品列表的servlet**/
public class GoodsListPageServlet extends HttpServlet {@Overridepublic void init() throws ServletException{super.init();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {int currentPage =Integer.parseInt( request.getParameter("currentPage"));//2. 根据指定的页数,去获取该页的数据回来//List<Goods> --- list.jspGoodsService service = new GoodsServiceImpl();PageBean<Goods> pageBean= service.findGoodsByPage(currentPage);request.setAttribute("pageBean", pageBean);//3. 跳转界面。request.getRequestDispatcher("list_page.jsp").forward(request, response);} catch (SQLException e) {e.printStackTrace();}}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}}

GoodsListServlet.java

package servlet;import java.io.IOException;
import java.sql.SQLException;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import bean.Goods;
import service.GoodsService;
import service.impl.GoodsServiceImpl;/*** 负责查询所有的商品信息。 然后呈现到list.jsp页面上。*/
public class GoodsListServlet extends HttpServlet {@Overridepublic void init() throws ServletException{super.init();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {//1. 查询出来所有的商品GoodsService service = new GoodsServiceImpl();List<Goods> list = service.findAll();//2. 先把数据存储到作用域中request.setAttribute("list", list);//3. 跳转页面request.getRequestDispatcher("list.jsp").forward(request, response);} catch (SQLException e) {e.printStackTrace();}}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doGet(request, response);}}

SearchGoodsServlet.java

package servlet;import java.io.IOException;
import java.sql.SQLException;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.catalina.valves.StuckThreadDetectionValve;import bean.Goods;
import service.GoodsService;
import service.impl.GoodsServiceImpl;/*** Servlet implementation class SearchStudentServlet*/
@SuppressWarnings("serial")
public class SearchGoodsServlet extends HttpServlet {@Overridepublic void init() throws ServletException{super.init();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");try {//1. 取到了要查询的关键数据 姓名  , 性别。String gname=  request.getParameter("gname");String sprice = request.getParameter("price");double price=Double.parseDouble(sprice);//2. 找service去查询GoodsService service = new GoodsServiceImpl();List<Goods> list = service.searchGoods(gname, price);System.out.println("list的大小是:"+list.size());for (Goods goods : list) {System.out.println("goods="+goods);}request.setAttribute("list", list);//3. 跳转界面。列表界面request.getRequestDispatcher("list.jsp").forward(request, response);} catch (SQLException e) {e.printStackTrace();}}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}}

src/main/java/util

JDBCUtil.java

package util;import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;import javax.sql.DataSource;import com.mchange.v2.c3p0.ComboPooledDataSource;public class JDBCUtil {static ComboPooledDataSource dataSource = null;static{dataSource = new ComboPooledDataSource();}public static DataSource getDataSource(){return dataSource;}/*** 获取连接对象*/public static Connection getConn() throws SQLException{return dataSource.getConnection();}/*** 释放资源*/public static void release(Connection conn , Statement st , ResultSet rs){closeRs(rs);closeSt(st);closeConn(conn);}public static void release(Connection conn , Statement st){closeSt(st);closeConn(conn);}private static void closeRs(ResultSet rs){try {if(rs != null){rs.close();}} catch (SQLException e) {e.printStackTrace();}finally{rs = null;}}private static void closeSt(Statement st){try {if(st != null){st.close();}} catch (SQLException e) {e.printStackTrace();}finally{st = null;}}private static void closeConn(Connection conn){try {if(conn != null){conn.close();}} catch (SQLException e) {e.printStackTrace();}finally{conn = null;}}}

TextUtil.java

package util;public class TextUtil {/*** 判断某一个字符串是否为空。*/public static boolean isEmpty(CharSequence s){return s==null || s.length() == 0;}
}

src/main/webapp

src/main/webapp/WEB-INF

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"><display-name>ch7_test</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><servlet><servlet-name>addServlet</servlet-name><servlet-class>AddServlet</servlet-class></servlet><servlet-mapping><servlet-name>addServlet</servlet-name><url-pattern>/AddServlet</url-pattern></servlet-mapping><servlet><servlet-name>showServlet</servlet-name><servlet-class>ShowServlet</servlet-class></servlet><servlet-mapping><servlet-name>showServlet</servlet-name><url-pattern>/ShowServlet</url-pattern></servlet-mapping><servlet><servlet-name>deleteServlet</servlet-name><servlet-class>servlet.DeleteServlet</servlet-class></servlet><servlet-mapping><servlet-name>deleteServlet</servlet-name><url-pattern>/DeleteServlet</url-pattern></servlet-mapping><servlet><servlet-name>goodsListPageServlet</servlet-name><servlet-class>servlet.GoodsListPageServlet</servlet-class></servlet><servlet-mapping><servlet-name>goodsListPageServlet</servlet-name><url-pattern>/GoodsListPageServlet</url-pattern></servlet-mapping><servlet><servlet-name>goodsListServlet</servlet-name><servlet-class>servlet.GoodsListServlet</servlet-class></servlet><servlet-mapping><servlet-name>goodsListServlet</servlet-name><url-pattern>/GoodsListServlet</url-pattern></servlet-mapping><servlet><servlet-name>searchGoodsServlet</servlet-name><servlet-class>servlet.SearchGoodsServlet</servlet-class></servlet><servlet-mapping><servlet-name>searchGoodsServlet</servlet-name><url-pattern>/SearchGoodsServlet</url-pattern></servlet-mapping>
</web-app>

add.jsp

<%@ page contentType="text/html;charset=UTF-8" %>
<html><head><title>register.jsp</title></head><body><jsp:include page="head.jsp" flush="true"/><font size=3><h1>请添加商品</h1><form action="AddServlet" method="get"><table><tr><td>商品名:</td><td><input type="text" name="gname"></td></tr><tr><td>价格:</td>    <td><input type="text" name="price"></td></tr><tr><td><input type="submit" value="提交"></td></tr></table></form></font><script>var Null= '<%=request.getParameter("Null")%>';if(Null=='yes'){alert("信息不得为空!");}</script></body>
</html>

head.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%String col = request.getParameter("col");
%>
<link href="style.css" rel="stylesheet" type="text/css"/>
<div id="top" class="layout"><img src="logo.jpg" width="100" height="100">
</div>
<div id="nav" class="layout">
<ul><li><a href="add.jsp">增加商品</a></li><li><a href="GoodsListPageServlet?currentPage=1">显示商品</a></li></ul>
</div>

list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@page import="bean.*" %><%@page import="java.util.*" %><%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表页面</title><script type="text/javascript">function doDelete(sid) {/* 如果这里弹出的对话框,用户点击的是确定,就马上去请求Servlet。 如何知道用户点击的是确定。如何在js的方法中请求servlet。 */var flag = confirm("是否确定删除?");if(flag){location.href="DeleteServlet?id="+id;}}
</script></head>
<body><jsp:include page="head.jsp"></jsp:include><form action="SearchStudentServlet" method="post"><table border="1" width="700"><tr ><td colspan="8">按名称查询:<input type="text" name="gname"/>&nbsp;按价格查询:<input type="text" name="price"/>&nbsp;&nbsp;&nbsp;<input type="submit" value="查询">&nbsp;&nbsp;&nbsp;<a href="add.jsp">添加</a></td></tr><tr align="center"><td>编号</td><td>商品名</td><td>价格</td></tr><c:forEach items="${pageBean.list }" var="goods"><tr align="center"><td>${goods.id }</td><td>${goods.gname }</td><td>${goods.data}</td><td><a href="#" onclick="doDelete(${goods.id})">删除</a></td></tr></c:forEach></table></form>
</body>
</html>

list_page.jsp

<%@ 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表页面</title><script type="text/javascript">function doDelete(sid) {/* 如果这里弹出的对话框,用户点击的是确定,就马上去请求Servlet。 如何知道用户点击的是确定。如何在js的方法中请求servlet。 */var flag = confirm("是否确定删除?");if(flag){//表明点了确定。 访问servlet。 在当前标签页上打开 超链接,//window.location.href="DeleteServlet?sid="+sid;location.href="DeleteServlet?id="+id;}}
</script></head>
<body><jsp:include page="head.jsp"></jsp:include><form action="SearchStudentServlet" method="post"><table border="1" width="700"><tr ><td colspan="8">按名称查询:<input type="text" name="gname"/>&nbsp;按价格查询:<input type="text" name="price"/>&nbsp;&nbsp;&nbsp;<input type="submit" value="查询">&nbsp;&nbsp;&nbsp;<a href="add.jsp">添加</a></td></tr><tr align="center"><td>编号</td><td>商品名</td><td>价格</td></tr><c:forEach items="${pageBean.list }" var="goods"><tr align="center"><td>${goods.id }</td><td>${goods.gname }</td><td>${goods.price }</td><td><a href="#" onclick="doDelete(${goods.id})">删除</a></td></tr></c:forEach><tr><td colspan="8">第 ${pageBean.currentPage } / ${pageBean.totalPage }&nbsp;&nbsp;每页显示${pageBean.pageSize }条  &nbsp;&nbsp;&nbsp;总的记录数${pageBean.totalSize } &nbsp;&nbsp;&nbsp;<c:if test="${pageBean.currentPage !=1 }"><a href="StudentListPageServlet?currentPage=1">首页</a>| <a href="StudentListPageServlet?currentPage=${pageBean.currentPage-1 }">上一页</a></c:if><c:forEach items="${pageBean.list }" var="goods"><tr align="center"><td>${goods.id }</td><td>${goods.gname }</td><td>${goods.price }</td><td><a href="#" onclick="doDelete(${goods.id})">删除</a></td></tr></c:forEach><c:if test="${pageBean.currentPage !=pageBean.totalPage }"><a href="StudentListPageServlet?currentPage=${pageBean.currentPage+1 }">下一页</a> | <a href="StudentListPageServlet?currentPage=${pageBean.totalPage }">尾页</a></c:if></td></tr></table></form>
</body>
</html>

main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
</head>
<body><jsp:include page="head.jsp" flush="true"/>
</body>
</html>

style.css

*{   margin: 0 ;padding: 0;
}
nav{    text-align: center; /*margin:0px auto;   /*没有宽度不能居中*/
}
ul{display: inline-block;/*ul设为内联元素便于居中*/
}ul li{float: left;list-style-type: none;  /*去掉圆点*/
}ul li + li{border-left: 1px solid #333;
}ul li a{background: #999;text-align: center;text-decoration: none;color: #000;display: block;padding: 3px 10px;
}ul li a:hover{color: red;background: #333;cursor: pointer;
}

java程序设计与j2ee中间件技术/软件开发技术(III)-大作业-采用MVC模式实现商品信息的查询显示(可以模糊查询)、增加和删除功能,商品表自拟,实现简单菜单操作和分页显示相关推荐

  1. 盘点直播直播平台软件开发技术中的编解码、直播协议、网络传输与简单实现

    盘点直播直播平台软件开发技术中的编解码.直播协议.网络传输与简单实现 编解码 视频封装格式就是我们通常所说的 .mp4,.flv,.ogv,.webm 等,它其实就是一个盒子,用来将实际的视频流以一定 ...

  2. 传道解惑 软件开发技术名词解密

    传道解惑 软件开发技术名词解密 序:去年为了总结自己所学习/接触过的技术,也顺便为初学者少走弯路指明一些方向,可惜后来诸事缠身未能继续,十分遗憾,现放到自己的BLOG上来鼓励自己将此继续下去. &qu ...

  3. 软件开发技术常用术语英中对照

    软件开发技术常用术语英中对照 A.I. 人工智能 A2A integration A2A整合 abstract 抽象的 abstract base class (ABC)抽象基类 abstract c ...

  4. 点评主流软件开发技术

    为什么80%的码农都做不了架构师?>>>    点评主流软件开发技术 http://soft.chinabyte.com/297/8698297.shtml ■ 河北秦皇岛 谷俭政 ...

  5. Intel 软件开发技术概要与在开发中的运用(讲解并行计算,多核心优化,以及Intel开发工具)

    英特尔有下列牛逼的开发工具与辅助套件,如何应用到实践中去,让自己的软件变得更加大,软件开发更加容易,软件拥有更多的性能呢 英特尔® 图形性能分析器 3.0 英特尔® Cloud Builder 英特尔 ...

  6. 20155310 《Java程序设计》实验三(敏捷开发与XP实践)实验报告

    20155310 <Java程序设计>实验三(敏捷开发与XP实践)实验报告 实验内容 1.XP基础 2.XP核心实践 3.相关工具 实验步骤 (一)敏捷开发与XP 1.敏捷开发 敏捷开发( ...

  7. 2020年度总结 | 葡萄城软件开发技术回顾

    本文由葡萄城技术团队原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 2020年是不平凡的一年,虽然疫情为整个社会都带来了巨大的冲击,但IT技术人 ...

  8. 软件开发技术联盟 - 图书系列资源

    软件开发技术联盟编著,清华大学出版社出版. 资料来源官方授权许可,详情见链接 资源出处 另外推荐学习资源网站: 清华出版社图书资源 以下为软件开发技术联盟所提供的图书配套资源,多为图书所带光盘资料,为 ...

  9. 2018-2019-2 20175227张雪莹《Java程序设计》实验三 《敏捷开发与XP实践》

    2018-2019-2 20175227张雪莹<Java程序设计> 实验三 <敏捷开发与XP实践> 实验报告封面 课程:Java程序设计 班级:1752班 姓名:张雪莹 学号: ...

最新文章

  1. java 动态获取类实例化_Java:使用反射动态实例化类
  2. 程序安装包制作工具 v1.0官方版
  3. Linux下的、1、2、2>1、dev/null黑洞文件
  4. php获取src,PHP读取文件
  5. java学习(142):file类的基本创建
  6. micro asyn wininet
  7. html表单实验总结,HTML表单总结
  8. 基于JAVA+SpringMVC+Mybatis+MYSQL的体育器材管理系统
  9. iproute2 对决 net-tools
  10. 02. Prefer consts, enums, and inlines to #defines
  11. 学python看谁的视频比较好-python学习视频好的有哪些
  12. 漏洞解决方案-短信炸弹攻击
  13. PB动态报表格式自由定义的实现
  14. 5个适合提升自己的自学网站,每一个都很强大, 适合职场人自我提升的学习网站,利用起来,离加薪更近一步
  15. YS_20190822_图像_Matlab_04
  16. UEFI标准应用程序模块--SMBIOS的读写
  17. oracle 10g rac 配置物理dataguard系列4,配置 Oracle 10g 单实例物理dataguard和逻辑standby...
  18. 餐饮行业最新的经营模式——私域运营案例
  19. 欧洲核子研究中心公布强子对撞机事故初步分析
  20. linux内核源码分析之CFS调度

热门文章

  1. 【网盘搜索小程序完整源码】微信QQ双端通用
  2. Linux之汇编复习篇(三)复杂指令及宏指令
  3. 家人们,谁懂啊!ChatGPT竟然可以写剧本?
  4. 2023成人自考报名费用大概多少 费用怎么交
  5. jQuery下载,eCharts组件下载
  6. Linux高级篇--Linux防火墙
  7. php中取整的函数,PHP取整函数的具体使用方法介绍_PHP教程
  8. 【BZOJ1005】【HNOI2008】明明的烦恼
  9. java 如何将数值型字符转换为数字_Java 如何将字符串转换为数字 专家详解
  10. 微信小程序跳到第三方地图