基于HTML+Servlet+JAVAWeb+MYSQL数据库的大麦网(增删改)

目录

一、运行效果

二、数据库

三、html编写

1、首页HomePage.jsp

2、筛选页index.jsp

3、登录login.jsp

4、添加add.jsp

5、修改updateItem.jsp

6、详细信息detail.jsp

四、Servlet

1、Dao

(1)DaMaiDao

(2)DaMaiI

(3)MysqlUtil

2、entity

item:

3、Servlet

(1)Login:

(2)Add:

(3)Select:

(4)Delete:

(5)Update:


一、运行效果

话不多说先上效果

首页:

筛选页:

修改:

添加:

删除:

详细信息:

二、数据库

一共用到了两个表:concert+item(user仅测试本例中未用到)

将id作为主键存在隐患,导致在后面的增删改中有部分项目不能进行操作,大家最好还是用id数字作为主键。

图片存储的是图片链接

三、html编写

总结构:

1、首页HomePage.jsp

(导航栏及中间分类模块借鉴了网页源码)


<%@ page import="java.sql.*" %>
<%@ page import="Dao.MysqlUtil" %><%--
  Created by IntelliJ IDEA.
  User: smile
  Date: 2023/10/19
  Time: 14:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="utf-8" />
<meta name="spm-id" content="a2oeg" />
<title>大麦网-全球演出赛事官方购票平台-100%正品、先付先抢、在线选座!</title>
<link rel="shortcut icon" href="//img.alicdn.com/tfs/TB1RxAHSmrqK1RjSZK9XXXyypXa-16-16.ico" type="image/x-icon">
<meta property="qc:admins" content="1733241067641511636" />
<meta name="keywords" content="演唱会,音乐会,话剧,体育比赛,儿童亲子,动漫,北京,门票,订票,购票,演出,先付先抢,在线选座,明星演唱会,在线订票,大麦网"/>
<meta name="description" content="大麦网-全球演出赛事官方购票平台-100%正品,安全快捷,为您提供演唱会、音乐会、话剧、体育比赛等多种门票在线订购服务,让您享受优质的购票体验!"/>
<link rel="stylesheet" href="//g.alicdn.com/damai/pc/1.0.53/p/index/index.css"/>
</head>
<body data-spm='home'><script>
    with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","userid=&aplus&pu_i=&asid=AQAAAADpFzFlqc/1CgAAAACEkk6A8gZK+A==&sidx=0&ckx=|",id="tb-beacon-aplus",src="//g.alicdn.com/alilog/mlog/aplus_v2.js")
</script>
<style>
    .grid-item img {
        width: 150px; /* 设置图片的宽度 */
        height: auto; /* 自动调整图片的高度以保持比例 */
    }
    .imgitem {
        width: 150px;
        height: auto;
       margin-left: 10px;
    }

    .tabtop13 td{
        background-color:#ffffff;
        height:25px;
        line-height:150%;
    }
    td.title{
        color:black;
        font-size: 14px;


    }
    p{
        color: lightgrey;
        font-size: 13px;
        margin: 10px 20px;
    }
    p.price{
        color: red;
        font-size: 20px;
    }
</style>
<div class="dm-header-wrap">
    <div class="dm-header-box" data-spm="top">
        <a href="a"><img class="i-logo" src="//img.alicdn.com/tfs/TB1fbVFfu3tHKVjSZSgXXX4QFXa-230-104.png" alt="大麦" /></a>
        <div class="location-header">
            <img class="i-icon-location" src="//img.alicdn.com/tfs/TB1XHDuxNGYBuNjy0FnXXX5lpXa-28-32.png" alt="定位" />
            <span class="city-location">全国</span>
            <img class="i-arrow-location" src="https://img.alicdn.com/tfs/TB1vnUBxStYBeNjSspaXXaOOFXa-20-12.png" alt="箭头" />
        </div>
        <div class="recommend-header">
            <a href="shouye" class="type-recommend select" data-spm="dhome">首页</a>
            <a href="fenlei" class="type-recommend" data-spm="dcategory">分类</a>
        </div>
        <div class="right-header" data-spm="nick">
            <div class="box-header user-header">
                <%-- 跳转到登陆界面--%>
                <a href="login.jsp" class="J_userinfo_img" data-spm="duserinfo">
                    <img class="i-box-header i-user" src="//img.alicdn.com/tfs/TB14UKCGQyWBuNjy0FpXXassXXa-54-54.png" /></a>
                    <div class="span-box-header name-user"></div>
                </a>

                <div class="login-user show">
                    <span class="span-box-header span-user" data-spm="dlogin">登录</span>
                </div>
            </div>

            <div class="box-header download-header">
                <img class="i-box-header i-download" src="//img.alicdn.com/tfs/TB1A9eIGKuSBuNjy1XcXXcYjFXa-54-54.png" alt="下载" />
                <span class="span-box-header">下载</span>
            </div>
        </div>
        <%--        搜索框--%>
        <div class="search-header" data-spm="searchtxt">
            <img class="i-search" src="//img.alicdn.com/tfs/TB1qv3jxGmWBuNjy1XaXXXCbXXa-34-36.png" alt="搜索" />
            <input class="input-search" placeholder="搜索明星、演出、体育赛事" data-spm="dsearchbtn" />
            <div class="btn-search" data-spm="dsearchbtn2">搜索</div>
            <div class="list-search-wrap">
                <div class="list-search">
                </div>
            </div>
        </div>

    </div>
</div>
<%--中间图片栏--%>
        <div id="slides" class="w1200">
            <div data-spm="banner" class="slides_container tab-content">
                <div class="tab-pannel">
                    <a data-spm="ditem_0" href="index.jsp" target="_blank">
                        <img src=https://img.alicdn.com/imgextra/i2/O1CN01FDNNT81xW9Vs6PSR9_!!6000000006450-0-tps-1200-320.jpg>
                    </a>
                </div>
            </div>
            <div class="prev" id="J_pre">
        <div class="arrow left"></div>
    </div>
    <div class="next" id="J_next">
        <div class="arrow"></div>
    </div></div></body></html>
<div class="dot current"></div>
</div>
</div>
<%--中间分类导航栏--%>
<div data-spm="category" class="category w1200">
    <a data-spm="ditem_0" href="index.jsp" class="category__list">
    <span class="category__icon category__icon__ych"></span>
    <p class="category__info">演唱会</p></a>
    <a data-spm="ditem_1" href="huajugeju" class="category__list">
    <span class="category__icon category__icon__gjhj"></span>
    <p class="category__info">话剧歌剧</p></a>
    <a data-spm="ditem_2" href="tiyu" class="category__list">
    <span class="category__icon category__icon__tyjj"></span>
    <p class="category__info">体育</p></a>
    <a data-spm="ditem_3" href="ertongqinzi" class="category__list">
    <span class="category__icon category__icon__qz"></span>
    <p class="category__info">儿童亲子</p></a>
    <a data-spm="ditem_4" href="zhanlanxiuxian" class="category__list">
    <span class="category__icon category__icon__zlxx"></span>
    <p class="category__info">展览休闲</p></a>
    <a data-spm="ditem_5" href="yinyuehui" class="category__list">
    <span class="category__icon category__icon__yyh"></span>
    <p class="category__info">音乐会</p></a>
    <a data-spm="ditem_6" href="quyuanzatan" class="category__list">
    <span class="category__icon category__icon__xsxq"></span>
    <p class="category__info">曲苑杂坛</p></a>
    <a data-spm="ditem_7" href="baleiwudao" class="category__list">
    <span class="category__icon category__icon__wdbl"></span>
    <p class="category__info">舞蹈芭蕾</p></a>
    <a data-spm="ditem_8" href="erciyuan" class="category__list">
    <span class="category__icon category__icon__dm"></span>
    <p class="category__info">二次元</p></a>
    <a data-spm="ditem_9" href="luyouzhanlan" class="category__list">
    <span class="category__icon category__icon__lyzl"></span>
    <p class="category__info">旅游展览</p>
</a>
</div>
<div data-spm="category" class="category w1200">
<a data-spm="ditem_0" href="index.jsp" class="category__list">
    <p class="category__info" >演唱会</p></a>
    <br>
            <table cellpadding="5" >
                <td ><img width="300" height="350"  src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i2/2251059038/O1CN01pIH9Du2GdSXQoMsHH_!!2251059038.jpg_q60.jpg_.webp"></td>
            <%
               Connection connection= MysqlUtil.getConnection();
                Statement statement = null;
                String sql;
                try{
                 
                    statement=connection.createStatement();
                    sql="SELECT *FROM item LIMIT 3";
                    ResultSet resultSet= statement.executeQuery(sql);
            %>
            <%
                while(resultSet.next()){
                    String img=resultSet.getString(1);
                    String id=resultSet.getString(2);
                    String adress=resultSet.getString(3);
                    String price= resultSet.getString(4);
                    String time = resultSet.getString(5);
            %>

                <td ><img class="imgitem" src="<%=img%>"></td>
                <td  class="title" ><%=id%>
                    <p> <%=adress%></p>
                    <p> <%=time%></p>
                    <p class="price"> <%=price%></p>
                   </td>

            <%
                    }
                }catch (SQLException e){
                    out.println("出现sql异常");
                }

            %></table>
</div>

<div data-spm="category" class="category w1200">
    <a data-spm="ditem_1" href="xxx" class="category__list">
        <p class="category__info" style="width: 100px">话剧歌剧</p></a>
    <table cellpadding="5" >
        <br>
        <td ><img width="300" height="350"  src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i1/2251059038/O1CN01U8x7Q92GdSXRCFfVF_!!2251059038.jpg"></td>


        <%
        sql="SELECT *FROM concert LIMIT 3";
        ResultSet resultSet= statement.executeQuery(sql);
    %>
    <%
        while(resultSet.next()){
            String img=resultSet.getString(1);
            String id=resultSet.getString(2);
            String adress=resultSet.getString(3);
            String price= resultSet.getString(4);
            String time = resultSet.getString(5);
    %>
        <td ><img class="imgitem" src="<%=img%>"></td>
        <td class="title"><%=id%><br><br>
         <p>   <%=adress%><br></p>
         <p><%=time%></p>
         <p class="price"><%=price%></p></td>
    <%}%>
    </table>

</div>







2、筛选页index.jsp

<%--
  Created by IntelliJ IDEA.
  User: smile
  Date: 2023/11/2
  Time: 13:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.*" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="Dao.MysqlUtil" %>
<%@ page import="java.net.URLEncoder" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="spm-id" content="a2oeg" />
        <title>大麦网-全球演出赛事官方购票平台-100%正品、先付先抢、在线选座!</title>
        <link rel="shortcut icon" href="//img.alicdn.com/tfs/TB1RxAHSmrqK1RjSZK9XXXyypXa-16-16.ico" type="image/x-icon">
        <meta property="qc:admins" content="1733241067641511636" />
        <meta name="keywords" content="演唱会,音乐会,话剧,体育比赛,儿童亲子,动漫,北京,门票,订票,购票,演出,先付先抢,在线选座,明星演唱会,在线订票,大麦网"/>
        <meta name="description" content="大麦网-全球演出赛事官方购票平台-100%正品,安全快捷,为您提供演唱会、音乐会、话剧、体育比赛等多种门票在线订购服务,让您享受优质的购票体验!"/>
        <link rel="stylesheet" href="//g.alicdn.com/damai/pc/1.0.53/p/index/index.css"/>
    </head>
<style>
    .grid-item img {
        width: 120px; /* 设置图片的宽度 */
        height: auto; /* 自动调整图片的高度以保持比例 */
    }
    .imgitem {
        width: 200px;
        height: 280px;
    }

    p.title{
        color:lightgrey;
        font-size: 20px;

    }
    span{
        color: #17073d;
        font-size: 15px;
        margin-left: 25px;

    }
    span:hover{
        color: white;
        background-color: deeppink;
    }
    .box1 {
        height:200px;
        width: 850px;
        background-color: white;
        margin-bottom: 0px;
        margin-top: 30px;
        margin-left: 200px;
        display:inline-block;
        border:solid 0.5px lightgrey;
    }
    .box2 {
        height: 520px;
        width: 250px;
        margin-top: 0px;
        display:inline-block;
        margin-left: 20px;
        background-color: white;
        border:solid 0.5px lightgrey;

        position: relative;
    }
    .box3 {
        height:auto;
        width: 850px;
        background-color: white;
        border:solid 0.5px lightgrey;
        position: absolute;
        left: 200px;/*相对浏览器左边偏移100px*/
        top:330px;
    }

    p.title{
        color:black;
        font-size: 15px;

    }

    p{
        color:darkgrey;
        font-size: 13px;
        margin: 10px 30px;
    }
    p.price{
        color: red;
        font-size: 20px;
    }
    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color:#f5f5f5;
    }

    li {
        float: left;
    }

    li a {
        display: block;
        color: black;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }

    li a:hover {
        background-color: white;
    }
    p1{
        color: #17073d;
        size: 10px;
        margin-left: 5px;

    }
    p2{
        color: darkgrey;
        size: 8px;
        margin-left: 5px;

    }
    p3{
        color: red;
        font-weight: bold;
        font-size:15px;
        margin-left: 5px;


    }
    .img1{
        margin-left: 10px;
         width:100px;
         height:150px;

    }
</style>
<div class="dm-header-wrap">
    <div class="dm-header-box" data-spm="top">
        <a href="HomePage.jsp"><img class="i-logo" src="//img.alicdn.com/tfs/TB1fbVFfu3tHKVjSZSgXXX4QFXa-230-104.png" alt="大麦" /></a>
        <div class="location-header">
            <img class="i-icon-location" src="//img.alicdn.com/tfs/TB1XHDuxNGYBuNjy0FnXXX5lpXa-28-32.png" alt="定位" />
            <span class="city-location">全国</span>
            <img class="i-arrow-location" src="https://img.alicdn.com/tfs/TB1vnUBxStYBeNjSspaXXaOOFXa-20-12.png" alt="箭头" />
        </div>


        <div class="recommend-header">
            <a href="HomePage.jsp" class="type-recommend select" data-spm="dhome">首页</a>
            <a href="fenlei" class="type-recommend" data-spm="dcategory">分类</a>
        </div>
        <div class="right-header" data-spm="nick">
            <div class="box-header user-header">
                <%-- 跳转到登陆界面--%>
                <a href="login.jsp" class="J_userinfo_img" data-spm="duserinfo">
                    <img class="i-box-header i-user" src="//img.alicdn.com/tfs/TB14UKCGQyWBuNjy0FpXXassXXa-54-54.png" /></a>
                <div class="span-box-header name-user"></div>
                </a>

                <div class="login-user show">
                    <span class="span-box-header span-user" data-spm="dlogin">登录</span>
                </div>
            </div>

            <div class="box-header download-header">
                <img class="i-box-header i-download" src="//img.alicdn.com/tfs/TB1A9eIGKuSBuNjy1XcXXcYjFXa-54-54.png" alt="下载" />
                <span class="span-box-header">下载</span>
            </div>
        </div>
        <%--        搜索框--%>
        <div class="search-header" data-spm="searchtxt">
            <img class="i-search" src="//img.alicdn.com/tfs/TB1qv3jxGmWBuNjy1XaXXXCbXXa-34-36.png" alt="搜索" />
            <input class="input-search" placeholder="搜索明星、演出、体育赛事" data-spm="dsearchbtn" />
            <div class="btn-search" data-spm="dsearchbtn2">搜索</div>
            <div class="list-search-wrap">
                <div class="list-search">
                </div>
            </div>
        </div>

    </div>
</div>

    <div data-spm="category" class="box1">
        <p class="title">城市:
            <a style="margin-left: 10px">当前选中城市</a>
            <span style="background-color: deeppink;color: white">北京</span>
        </p>
        <p style="margin-top: 10px">
            <span style="margin-left: 75px;background-color: deeppink;color: white"> 全部 </span>
            <span > 北京 </span>
            <span> 上海 </span>
            <span> 重庆 </span>
            <span> 杭州 </span>
            <span> 成都 </span>
            <span> 天津 </span>
            <span> 深圳 </span>
            <span> 广州 </span>
            <span> 苏州 </span>


        </p>
        <p style="margin-left: 80px;margin-top:10px " >
            <span> 西安 </span>
            <span> 武汉 </span>
            <span> 长沙 </span>
            <span> 郑州 </span>
            <span> 沈阳 </span>
            <span> 青岛 </span>
            <span> 厦门</span>
            <span> 合肥 </span>
            <span> 昆明 </span>
            <span> 福州 </span>
        </p>

        <p class="title" style="margin-top: 10px">分类:
            <span style="background-color: deeppink;color: white"> 全部 </span>
            <span> 音乐会 </span>
            <span> 曲苑杂坛 </span>
            <span> 话剧歌剧 </span>
            <span> 展览休闲 </span>
            <span> 舞蹈芭蕾</span>
            <span> 体育 </span>
            <span> 其他</span>
        </p>
        <p class="title" style="margin-top: 10px">子类:
            <span style="background-color: deeppink;color: white"> 全部 </span>
            <span> livehouse </span>
            <span> 音乐节 </span>
            <span> 其他</span>
        </p>
        <p class="title" style="margin-top: 10px">时间:
            <span style="background-color: deeppink;color: white"> 全部 </span>
            <span>今天</span>
            <span> 明天 </span>
            <span> 本周末 </span>
            <span> 一个月内</span>
        </p>


    </div>

    <div class="box2" >
      <ul>
          <li><p style="color: #17073d;font-size: 15px">您可能还喜欢</p></li>
          
      </ul>
<table >
<tr >
    <td >
        <img style="margin-left: 10px" src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i1/2251059038/O1CN01hBMYXY2GdSXUiQZaF_!!2251059038.png_q60.jpg_.webp" width="100px"height="150">
    </td>
    <td style="margin-left: 2px">
        <p1 style="color:#000" >「 后来的人」王贰浪<br></p1>
        <p2> 北京市<br></p2>
        <p2> 2024.01.13 周六<br><br></p2>
        <p3>200</p3>
    </td>
    </tr>
    <tr >
        <td >
            <img class="img1" src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i2/2251059038/O1CN01pIH9Du2GdSXQoMsHH_!!2251059038.jpg_q60.jpg_.webp" >
        </td>
        <td style="margin-left: 2px">
            <p1 style="color:#000" >12.23圣诞狂欢电音节<br></p1>
            <p2> 北京市<br></p2>
            <p2> 2023.12.23 周六 <br><br></p2>
            <p3>79-399</p3>
        </td>
    </tr>
    <tr >
        <td >
            <img class="img1" src="https://img.alicdn.com/bao/uploaded/i3/2251059038/O1CN01rR0tnV2GdSXNsMdn9_!!2-item_pic.png_q60.jpg_.webp"height="150">
        </td>
        <td style="margin-left: 2px">
            <p1 style="color:#000" >我回来了」南拳妈妈巡回演唱会<br></p1>
            <p2> 北京市<br></p2>
            <p2> 2023.12.12 周二<br><br></p2>
            <p3>499-699</p3>
        </td>
    </tr>

</table>


    </div>



<%
    int i=0;
    int pages=0;            //待显示页面
    int count=0;            //总条数
    int totalpages=0;        //总页数
    int limit=8;            //每页显示记录条数

    Connection conn = MysqlUtil.getConnection();

    PreparedStatement pstmt=conn.prepareStatement("select count(*) from item");
    ResultSet resultSet=pstmt.executeQuery();
    if(resultSet.next()){
        count =resultSet.getInt(1);
    }
    totalpages = (int)Math.ceil(count/(limit*1.0));
    String strPage = request.getParameter("pages");
    if (strPage == null) {
        pages = 1;
    } else {
        try{
            pages = java.lang.Integer.parseInt(strPage);
        }catch(Exception e){
            pages = 1;
        }

        if (pages < 1){
            pages = 1;
        }
        if (pages > totalpages){
            pages = totalpages;
        }
    }

    resultSet = pstmt.executeQuery("select * from item order by id limit " + (pages - 1) * limit + "," + limit);
    out.print(" <div  data-spm=\"category\" class=\"box3\">");
    out.print("<table style=\"border-collapse:separate; border-spacing:10px;\" >"+
            "   <ul>" +
            "        <li><a class=\"active\" href=\"#home\">相关度排序</a></li>" +
            "        <li><a href=\"#news\">推荐排序</a></li>" +
            "        <li><a href=\"#contact\">最近开场</a></li>" +
            "        <li><a href=\"#about\">最新上架</a></li>" +
            "        <li><a href=\"addItem.jsp\" > 添加产品</a></ul>");
    while(resultSet.next()){
        i++;
        out.print("<tr><td>"+
                "<img  class=imgitem src="+resultSet.getString(1)+">"+
                "</td><td style=\"margin-left: 10px\" ><p class=\"title\">"+resultSet.getString(2)+
                "</p><p>"+resultSet.getString(3)+
                "<br></p><p>"+resultSet.getString(5)+
                "<br></p><p class=\"price\">"+resultSet.getString(4)+
                "</p><p style=\"margin-top: 10px\"> <a href="+request.getContextPath()+"/ItemSelectServlet?id="+ resultSet.getString(2)+">修改</a>"+
                " <a href=detail.jsp>查看详情</a>"+
                " <a href="+request.getContextPath()+"/ItemDeleteServlet?id="+resultSet.getString(2)+">删除</a></p>"+
                "</td></tr>");


    }out.print("</table>");
    if(i!=0){


    }else{
        out.print("搜索不到!");}
    resultSet.close();
    pstmt.close();
    conn.close();


%>
<form name="f1" method="POST" action="index.jsp" font-size="50">
    <table border="0" align="center">
        <tr  >

            <td>第<%=pages%>页 共<%=totalpages%>页 <a href="index.jsp?pages=1">首页</a></td>
            <td><a href="index.jsp?pages=<%=(pages<1)?pages:(pages-1) %>"> 上一页</a></td>
            <td><a href="index.jsp?pages=<%=(pages>=totalpages)?totalpages:(pages+1)%>"> 下一页</a></td>
            <td><a href="index.jsp?pages=<%=totalpages%>">最后一页</a></td>
            <td>转到第:<input type="text" name="pages" size="7">页<input type="submit" value="GO" name="cndok"></td>
        </tr>
    </table>
</form>
</body>
</html>

3、登录login.jsp



<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="shortcut icon" href="//img.alicdn.com/tfs/TB1RxAHSmrqK1RjSZK9XXXyypXa-16-16.ico" type="image/x-icon">
    <title>大麦登录</title>
    <link rel="stylesheet" href="//g.alicdn.com/mui/zebra-dm-pc-login/4.0.14/index-pc.css" />
</head>
<style>
    .pcbar{
        height:90px
    }
    .pcbar__bd{
        width:1200px;
        margin:0 auto;
        height:90px
    }
    .pcbar__bd__logo img{
        float:left;
        *display:inline;
        margin-top:24px;
        width:108px;
        height:48px
    }
    .button {
        background-color: deeppink;
        border: none;
        color: white;
        padding: 15px 32px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        margin: 4px 2px;
        cursor: pointer;
    }
   </style>
</style>
<div class="pcbar">
    <div class="pcbar__bd w1200">
        <a href="HomePage.jsp" class="pcbar__bd__logo">
            <img src="//img.alicdn.com/tfs/TB19yBbRSzqK1RjSZFLXXcn2XXa-230-104.png"/>
        </a>
    </div>
</div>
<!--页面头部 end-->
<style>
    .zebra-dm-pc-login{
    background:linear-gradient(to right, #17073d, #17073d, #17073d)
}
</style>
        <div class="zebra-dm-pc-login" data-mod-name="mui/zebra-dm-pc-login/index-pc" data-config="{}" data-async-load="true" >
            <div class="login" >
                <a  class="ad">
                <%-- 背景图--%>
                    <img src="https://img.alicdn.com/tfs/TB1NkOydrus3KVjSZKbXXXqkFXa-720-400.png_q75.jpg" alt="" />
                </a>
                <div id="alibaba-login-iframe">
                    <p><h2>用户登录</h2></p>
                    <form name="form1" action="LoginServlet" method="post" >
                        <p> 用户名:<input type="text" name="username" ></p>
                        <p> 密码:<input type="password" name="password"></p>
                        <input class="button" type="submit" name="submit" value="登录"></input>
                    </form>
            </div>
        </div>
    </div>
</div>
</div>
</body>
</html>

4、添加add.jsp

<%--
  Created by IntelliJ IDEA.
  User: smile
  Date: 2023/10/21
  Time: 13:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="shortcut icon" href="//img.alicdn.com/tfs/TB1RxAHSmrqK1RjSZK9XXXyypXa-16-16.ico" type="image/x-icon">
    <title>添加项目</title>
    <link rel="stylesheet" href="//g.alicdn.com/mui/zebra-dm-pc-login/4.0.14/index-pc.css" />
</head>
<style>
    .pcbar{
        height:90px
    }
    .pcbar__bd{
        width:1200px;
        margin:0 auto;
        height:90px
    }
    .pcbar__bd__logo img{
        float:left;
        *display:inline;
        margin-top:24px;
        width:108px;
        height:48px
    }
    .button {
        background-color: deeppink;
        border: none;
        color: white;
        padding: 15px 32px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        margin: 4px 2px;
        cursor: pointer;
    }
</style>
</style>
<div class="pcbar">
    <div class="pcbar__bd w1200">
        <a href="HomePage.jsp" class="pcbar__bd__logo">
            <img src="//img.alicdn.com/tfs/TB19yBbRSzqK1RjSZFLXXcn2XXa-230-104.png"/>
        </a>
    </div>
</div>
<!--页面头部 end-->
<style>
    .zebra-dm-pc-login{
        background:linear-gradient(to right, #17073d, #17073d, #17073d)
    }
</style>
<div class="zebra-dm-pc-login" data-mod-name="mui/zebra-dm-pc-login/index-pc" data-config="{}" data-async-load="true" >
    <div class="login" >
        <a  class="ad">
            <%-- 背景图--%>
            <img src="https://img.alicdn.com/tfs/TB1NkOydrus3KVjSZKbXXXqkFXa-720-400.png_q75.jpg" alt="" />
        </a>
        <div id="alibaba-login-iframe">
            <p><h2>添加项目</h2></p>
            <form action="ItemAddServlet" method="post">
                <p> 产品图片:<input type="text" name="img" ></p>
                <p> 产品名称:<input type="text" name="id"></p>
                <p> 表演地点:<input type="text" name="address"></p>
                <p> 产品价格:<input type="text" name="price"></p>
                <p> 表演时间:<input type="text" name="time"></p>
                <input class="button" type="submit" name="addItem" value="添加产品">
            </form>
        </div>
    </div>
</div>
</div>
</div>
</body>
</form>
</body>
</html>

5、修改updateItem.jsp

<%--
  Created by IntelliJ IDEA.
  User: smile
  Date: 2023/10/21
  Time: 13:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="Servlet.ItemQueryServlet"%>
<%@ page import="entity.Item" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<html>
<head>
    <link rel="shortcut icon" href="//img.alicdn.com/tfs/TB1RxAHSmrqK1RjSZK9XXXyypXa-16-16.ico" type="image/x-icon">
    <title>更新项目</title>
    <link rel="stylesheet" href="//g.alicdn.com/mui/zebra-dm-pc-login/4.0.14/index-pc.css" />
</head>
<style>
    .pcbar{
        height:90px
    }
    .pcbar__bd{
        width:1200px;
        margin:0 auto;
        height:90px
    }
    .pcbar__bd__logo img{
        float:left;
        *display:inline;
        margin-top:24px;
        width:108px;
        height:48px
    }
    .button {
        background-color: deeppink;
        border: none;
        color: white;
        padding: 15px 32px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        margin: 4px 2px;
        cursor: pointer;
    }
</style>
</style>
<div class="pcbar">
    <div class="pcbar__bd w1200">
        <a href="HomePage.jsp" class="pcbar__bd__logo">
            <img src="//img.alicdn.com/tfs/TB19yBbRSzqK1RjSZFLXXcn2XXa-230-104.png"/>
        </a>
    </div>
</div>
<!--页面头部 end-->
<style>
    .zebra-dm-pc-login{
        background:linear-gradient(to right, #17073d, #17073d, #17073d)
    }
</style>

<div class="zebra-dm-pc-login" data-mod-name="mui/zebra-dm-pc-login/index-pc" data-config="{}" data-async-load="true" >
    <div class="login" >
        <a  class="ad">
            <%-- 背景图--%>
            <img src="https://img.alicdn.com/tfs/TB1NkOydrus3KVjSZKbXXXqkFXa-720-400.png_q75.jpg" alt="" />
        </a>
        <div id="alibaba-login-iframe">
            <p><h2>更新项目</h2></p>
<%
    Item item = (Item) request.getAttribute("item");
%>
            <form action="<%=request.getContextPath()%>/ItemUpdateServlet"  method="get" >
                <p> 产品图片:<input type="text" name="img"  value="<%=item.getImg()%>"></p>
                <p> 产品名称:<input type="text" name="id" readonly value="<%=item.getId()%>"></p>
                <p> 表演地点:<input type="text" name="address" value="<%=item.getAdress()%>"></p>
                <p> 产品价格:<input type="text" name="price"value="<%=item.getPrice()%>"></p>
                <p> 表演时间:<input type="text" name="time"value="<%=item.getTime()%>"></p>
                <input class="button" type="submit" name="updateItem" value="更新产品">
            </form>
        </div>
    </div>
</div>


</div>
</div>
</body>
</form>
</body>
</html>

6、详细信息detail.jsp

这里为了简便我只写了一个静态页面,也就是说这个界面是写死的,不会随着项目的不同而改变。存在可以优化的地方。

<%--
  Created by IntelliJ IDEA.
  User: smile
  Date: 2023/10/31
  Time: 19:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<title>【成都】薛之谦“天外来物”巡回演唱会-成都站【网上订票】- 大麦网</title>
<meta name="keywords" content="【成都】薛之谦“天外来物”巡回演唱会-成都站,大麦网"/>
<meta name="description" content="大麦网(Damai.cn)【成都】薛之谦“天外来物”巡回演唱会-成都站将于2023.11.03-11.04在成都东安湖体育公园主体育场上演,大麦网为【成都】薛之谦“天外来物”巡回演唱会-成都站门票代理,更多门票价格及订票详情请咨询大麦网。"/>
<meta charset="utf-8">
<meta name="spm-id" content="a2oeg"/>
<meta name='aplus-auto-exp-visible' content='0.5'>
<meta name='aplus-auto-exp-duration' content='500'>
<meta name='aplus-auto-exp' content='[{"logkey":"/damai_pc.pcexp.exp","tag":"p","filter":"class=perform__unsale__title","props":["item_id","clicktitle"]},{"logkey":"/damai_pc.pcexp.exp","tag":"div","filter":"class=perform__countdown__title","props":["item_id","clicktitle"]}]'>
<link rel="stylesheet" href="//g.alicdn.com/damai/??/vue-pc/0.0.79/vendor.css,vue-pc/0.0.79/perform/perform.css"/>
<link rel="stylesheet" href="//g.alicdn.com/??damai/pc/1.0.53/p/head/index.css,damai/pc/1.0.53/p/footer/index.css"/>
<link rel="shortcut icon" href="//img.alicdn.com/tfs/TB1RxAHSmrqK1RjSZK9XXXyypXa-16-16.ico" type="image/x-icon">

<link rel="stylesheet" href="https://cdn.staticfile.org/foundation/5.5.3/css/foundation.min.css">
</head>
<style>
    .box1 {
        height:300px;
        width:900px;
        background-color: blanchedalmond;
        margin-top: 20px;
        margin-left: 50px;
        display:inline-block;

    }
    .box2 {
        height: 550px;
        width: 300px;
        display:inline-block;
        margin-left: 30px;


        position: relative;
    }
    .box3 {
        height:1000px;
        width: 900px;
        background-color: white;
        display:inline-block;
        border:solid 0.5px lightgrey;
        position: absolute;
        left: 50px;/*相对浏览器左边偏移100px*/
        top:500px;
    }
    p{
        color:darkgrey;
        font-size: 13px;
        margin: 10px 30px;
    }
    p.title{
        color:black;
        font-size: 15px;

    }
    p1{
        color: #17073d;
        size: 10px;
        margin-left: 5px;

    }
    p2{
        color: darkgrey;
        size: 8px;
        margin-left: 5px;

    }
    p3{
        color: red;
        font-weight: bold;
        font-size:15px;
        margin-left: 5px;


    }
    .img1{
        margin-left: 10px;
        width:150px;
        height:150px;

    }
    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color:#f5f5f5;
    }

    li {
        float: left;
    }

    li a {
        display: block;
        color: black;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }

    li a:hover {
        background-color: white;
    }

</style>

<body>
<!--<div class="dm-header-banner"></div>-->
<div class="dm-header-wrap">
    <div class="dm-header-box" data-spm="top">
        <a href="HomePage.jsp"><img class="i-logo" src="//img.alicdn.com/tfs/TB1fbVFfu3tHKVjSZSgXXX4QFXa-230-104.png" alt="大麦" /></a>
        <div class="location-header">
            <img class="i-icon-location" src="//img.alicdn.com/tfs/TB1XHDuxNGYBuNjy0FnXXX5lpXa-28-32.png" alt="定位" />
            <span class="city-location">全国</span>
            <img class="i-arrow-location" src="https://img.alicdn.com/tfs/TB1vnUBxStYBeNjSspaXXaOOFXa-20-12.png" alt="箭头" />
            <div class="city-header-wrap">
                <div class="city-header" data-spm="city">
                    <div class="now-city">
                        <span class="title-city">当前城市:</span>
                        <span class="name-city select-city">全国</span>
                    </div>
                    <div class="hot-city">
                        <span class="title-city">热门城市:</span>
                        <div class="list-other"></div>
                    </div>
                    <div class="other-city">
                        <span class="title-city">其他城市:</span>
                        <div class="list-other"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="recommend-header">
            <a href="/" class="type-recommend select" data-spm="dhome">首页</a>
            <a href="/" class="type-recommend" data-spm="dcategory">分类</a>

        </div>
        <div class="right-header" data-spm="nick">
            <div class="box-header user-header">
                <a href="javascript:void(0)" class="J_userinfo_img" data-spm="duserinfo"><img class="i-box-header i-user" src="//img.alicdn.com/tfs/TB14UKCGQyWBuNjy0FpXXassXXa-54-54.png" /></a>
                <a href="//passport.damai.cn/accountinfo/myinfo" class="J_userinfo_name" data-spm="duserinfo">
                    <div class="span-box-header name-user"></div>
                </a>
                <div class="login-user show">
                    <span class="span-box-header span-user" data-spm="dlogin">登录</span>
                </div>
                <div class="list-wrap">
                    <div class="list-login">
                        <a href="//passport.damai.cn/accountinfo/myinfo" class="li-login select" data-spm="duserinfo">个人信息</a>
                        <a href="//passport.damai.cn/accountinfo/accountsetting" class="li-login" data-spm="daccountsetting">账号设置</a>
                        <a href="//orders.damai.cn/orderList" class="li-login" data-spm="dordermanage">订单管理</a>
                        <a href="//passport.damai.cn/account/logout" data-spm="dexit" class="li-login out-login">退出登录</a>
                    </div>
                </div>
            </div>
            <div class="box-header download-header">
                <img class="i-box-header i-download" src="//img.alicdn.com/tfs/TB1A9eIGKuSBuNjy1XcXXcYjFXa-54-54.png" alt="下载" />
                <span class="span-box-header">下载</span>
                <div class="ewm-download">
                    <img class="i-ewm" src="//gw.alicdn.com/imgextra/i2/O1CN01WXpWzZ1r0C9fGPCfv_!!6000000005568-2-tps-2440-2440.png" />
                </div>
            </div>
        </div>
        <div class="search-header" data-spm="searchtxt">
            <img class="i-search" src="//img.alicdn.com/tfs/TB1qv3jxGmWBuNjy1XaXXXCbXXa-34-36.png" alt="搜索" />
            <input class="input-search" placeholder="搜索明星、演出、体育赛事" data-spm="dsearchbtn" />
            <div class="btn-search" data-spm="dsearchbtn2">搜索</div>
            <div class="list-search-wrap">
                <div class="list-search">
                </div>
            </div>
        </div>

    </div>
</div>
<div class="box1">
<table>

    <td colspan="3">
     <img  src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i4/2251059038/O1CN01pnTA8y2GdSXGcXNTo_!!2251059038.jpg_q60.jpg_.webp" >
</td>
       <td >
           <ul style="background-color: white">
        <h2><li>【成都】薛之谦“天外来物”巡回演唱会-成都站</li></h2>
         时间:2023.11.03-11.04<br>
           场馆:成都市 | 成都东安湖体育公园主体育场
               <br>
          城市:成都站<br>
               价格:<p3>317-1717</p3>
          </ul>
       </td>
    </table>
</div>
<div class="box2" >
    <ul >
        <li ><p style="color: #17073d;font-size: 15px">您可能还喜欢</p></li>

    </ul>
    <table >
        <tr >
            <td >
                <img class="img1" src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i1/2251059038/O1CN01hBMYXY2GdSXUiQZaF_!!2251059038.png_q60.jpg_.webp" width="100px"height="150">
            </td>
            <td style="margin-left: 2px">
                <p1 style="color:#000" >「 后来的人」王贰浪<br></p1>
                <p2> 北京市<br></p2>
                <p2> 2024.01.13 周六<br><br></p2>
                <p3>168-398</p3>
            </td>
        </tr>
        <tr >
            <td >
                <img class="img1" src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i2/2251059038/O1CN01pIH9Du2GdSXQoMsHH_!!2251059038.jpg_q60.jpg_.webp" >
            </td>
            <td style="margin-left: 2px">
                <p1 style="color:#000" >12.23圣诞狂欢电音节<br></p1>
                <p2> 北京市<br></p2>
                <p2> 2023.12.23 周六 <br><br></p2>
                <p3>79-399</p3>
            </td>
        </tr>
        <tr >
            <td >
                <img class="img1" src="https://img.alicdn.com/bao/uploaded/i3/2251059038/O1CN01rR0tnV2GdSXNsMdn9_!!2-item_pic.png_q60.jpg_.webp"height="150">
            </td>
            <td style="margin-left: 2px">
                <p1 style="color:#000" >我回来了」南拳妈妈巡回演唱会<br></p1>
                <p2> 北京市<br></p2>
                <p2> 2023.12.12 周二<br><br></p2>
                <p3>499-699</p3>
            </td>
        </tr>

    </table>
</div>

<div  class="box3" >
    <table style="border-collapse:separate; border-spacing:10px;" >

            <ul class="a">
                <li class="lia" ><a class="active" href="#home">项目详情</a></li>
                <li class="lia" ><a href="#news">观演须知</a></li>
                <li><a href="#contact">购票须知</a></li>
            </ul>
      <h2 >薛之谦“天外来物”巡演持续上演 2023歌单造型全升级</h2>
   <div style="margin-top: 10px">自 2021年巡演开启,“天外来物”不断在观演人次与开票数据上创造着惊喜。“天外来物”演出现场,既有创新式实景搭建硬核科技感的舞美,又有薛之谦高质量唱演呈现出的精妙构思的音乐故事;更有薛之谦自2006年发布同名专辑《薛之谦》以来,长达17年在音乐领域的深耕与坚持。《认真的雪》、《演员》、《丑八怪》、《刚刚好》等代表作脍炙人口、传唱度非凡,万人合唱的盛况场场上演。</div>

    <img src="https://img.alicdn.com/imgextra/i3/2251059038/O1CN0122Eg1a2GdSX7lgsPS_!!2251059038.png_q60.jpg_.webp">

    <div style="margin-top: 10px;margin-left: 20px">“天外来物”寓意颇丰,视觉设计未来感炸裂
此次巡演以薛之谦第十一张专辑《天外来物》命名,并沿用“天外来物”作为演唱会的主题概念,包含着薛之谦对于音乐和生活的独到见解。快节奏的生活使得许多人容易忽略生活中的美好而变得急功近利,《天外来物》的核心概念正是想借音乐的抒发,希望每个人都能够在心中保留一块单纯善良的净土。</div>
<img src="https://img.alicdn.com/imgextra/i2/2251059038/O1CN01PzsLEg2GdSXD5LuQg_!!2251059038.png_q60.jpg_.webp">
    <div style="margin-top: 10px">除了在音乐上延续了“薛式风格”,此次演唱会中还加入了各种全新的视觉元素,三巡的主视觉海报便是充满科技感,薛之谦的眼中藏着电子机械的纹理,脸部皮肤内嵌芯片,并且还写有编号NO.0717,而这串数字正是薛之谦的生日,无论是从上述的细节,还是从薛之谦冷然空洞的表情神态,都呈现出完整的机器人元素,这也恰恰暗示了薛之谦此次演唱会中“0717号星际执行官”的身份。</div>

<img src="https://img.alicdn.com/imgextra/i3/2251059038/O1CN01PBiIRo2GdSX7jZUtz_!!2251059038.png_q60.jpg_.webp">
<div style="margin-top: 10px">实力歌手演绎视听盛宴,“唱”“演”结合引全网期待
    本次薛之谦巡回演唱会的舞美效果也是费了一番心思,精心打造了充满未来感的舞台呈现,实景搭建了巨型宇宙飞船、欲望之塔、旋转木马等场景,一方面呼应天外来物的主题,另一方面,也贴合了演唱会的“主线剧情”发展,以“唱”“演”结合的方式创新将演唱会带入全新维度,为观众带来真正意义上的视听盛宴。</div>
<img src="https://img.alicdn.com/imgextra/i4/2251059038/O1CN01Dn8ZY12GdSX5CeyaG_!!2251059038.png_q60.jpg_.webp">

<div style="margin-top: 10px"><h4>购票须知</h4>
    <h5>限购规则<br></h5>
    每笔订单最多购买4张、每个账号最多购买4张。</div>

    <div style="margin-top: 10px"><h5>退票/换票规则<br></h5>

        本项目支持有条件退款,若需要收取退票手续费,将以用户实际支付票款为基准收取。基于项目主办方提供的退票政策不同,具体可支持用户申请退款的情形请详见该项目详情页退票政策相关说明或公告。</div>

    <div style="margin-top: 10px"><h5>入场规则<br></h5>

        支持多种票品验票后入场,如证件电子票。</div>

    <div style="margin-top: 10px"><h5>儿童购票<br></h5>

        儿童一律凭票入场</div>

    <div style="margin-top: 10px"><h5>实名购票规则<br></h5>

        一张门票对应一个证件;证件支持:护照/港澳台居民居住证/台湾居民来往大陆通行证/港澳居民来往内地通行证/身份证</div>


</table>
</div>
</body>
</html>

四、Servlet

总结构

1、Dao

(1)DaMaiDao
package Dao;

import entity.Item;

import java.sql.SQLException;
import java.util.List;

public interface DaMaiDao {

   
    public boolean addItem(Item item) throws SQLException;
    public boolean deleteItem(String id) throws SQLException;
    public int update(Item item);
    public Item selectById(String id);
}
(2)DaMaiI
package Dao;

import entity.Item;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class DaMaiI implements DaMaiDao{

    PreparedStatement preparedStatement=null;
    Connection connection=MysqlUtil.getConnection();

    @Override
    public boolean addItem(Item item) {
        boolean flag=false;
        try {
            StringBuilder sql = new StringBuilder("insert  into item  value(?,?,?,?,?)");
            preparedStatement = connection.prepareStatement(sql.toString());
            //可以发送SQL语句到数据库
            preparedStatement.setString(1, item.getImg());
            preparedStatement.setString(2, item.getId());
            preparedStatement.setString(3,item.getAdress());
            preparedStatement.setString(4, item.getPrice());
            preparedStatement.setString(5,item.getTime());
           int i= preparedStatement.executeUpdate();
           if(i>0){
               flag=true;
           }
        } catch (SQLException e) {
            e.printStackTrace();
        }


        return flag;
    }

    @Override
    public boolean deleteItem(String id)  {
        boolean flag=false;
        try {
       String sql="delete  from item where id=?";
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,id);
           int i= preparedStatement.executeUpdate();
           if(i>0){
               flag=true;
           }
        } catch (SQLException e) {
            System.out.println("删除失败!");
            e.printStackTrace();
        }
        return flag;

    }

    @Override
    public int update(Item item) {
       int i=0;
        try {
            String sql = "update item  set img=?,address=?,price=?,time=? where id=?";
            preparedStatement=connection.prepareStatement(sql);
            preparedStatement.setString(1,item.getImg());
            preparedStatement.setString(2,item.getAdress());
            preparedStatement.setString(3,item.getPrice());
            preparedStatement.setString(4,item.getTime());
            preparedStatement.setString(5,item.getId());
            i=preparedStatement.executeUpdate();
            connection.close();
            preparedStatement.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
      return i;

    }

    public Item selectById(String id) {
        Item item=null;
        String sql="select* from item where id=?";

        try {
            PreparedStatement preparedStatement=connection.prepareStatement(sql);
            preparedStatement.setString(1,id);
            ResultSet resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                item = new Item();
                item.setId(resultSet.getString("id"));
                item.setImg(resultSet.getString("Img"));
                item.setAdress(resultSet.getString("address"));
                item.setPrice(resultSet.getString("price"));
                item.setTime(resultSet.getString("time"));

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
     return item;

    }


}
(3)MysqlUtil
package Dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MysqlUtil {

    static Connection connection=null;
    public  static Connection getConnection() {
         String driverName = "com.mysql.cj.jdbc.Driver";
         String dbURL = "jdbc:mysql://127.0.1:3306/damai";
         String userName = "root";
         String userPwd = "030466zy";
        try {

            Class.forName(driverName);//加载数据库
            connection = DriverManager.getConnection(dbURL, userName, userPwd);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;

    }
}

2、entity

item:
package entity;

public class Item {
    private String img;
    private String id;
    private String adress;
    private String price;
    private String time;


    public Item() {

    }

    public Item(String img, String id, String adress, String price, String time) {
        this.img = img;
        this.id = id;
        this.adress = adress;
        this.price = price;
        this.time = time;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }


    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }
}

3、Servlet

(1)Login:
package Servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    public final static long serialVersionUID=0;
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 将输出转换为中文
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        // 设置输出为中文
        response.setCharacterEncoding("UTF-8");

        HttpSession session=request.getSession();
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        //验证登录

       if(username.equals("123")&&password.equals("abcd")){
           response.getWriter().write("<h2><center>Sucessful!Go to HomePage!</h2></center>");
           response.setHeader("refresh", "3;url=HomePage.jsp");
//           request.getRequestDispatcher("/HomePage.jsp").forward(request,response);
       }else {
           response.getWriter().write("<h2><center>Failed!Go to loginPage!</h2></center>");
           //设置3秒钟跳转
           response.setHeader("refresh", "3;url=login.jsp?spm=a2oeg.home.nick.duserinfo.5baf23e1fEGfaB");

       }
    }
}
(2)Add:
package Servlet;

import Dao.DaMaiI;
import entity.Item;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ItemAddServlet", value = "/ItemAddServlet")
public class ItemAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       request.setCharacterEncoding("utf-8");
       response.setContentType("text/html;charset=utf-8");
        String img=request.getParameter("img");
        String id=request.getParameter("id");
        String address=request.getParameter("address");
        String price=request.getParameter("price");
        String time=request.getParameter("time");
        Item item = new Item();
        item.setImg(img);
        item.setId(id);
        item.setAdress(address);
        item.setPrice(price);
        item.setTime(time);
        DaMaiI add=new DaMaiI();

        if(add.addItem(item)){
            response.getWriter().write("<h2><center>Successful! Return to the previous screen in three seconds!</center></h2>");
            response.setHeader("refresh", "3;url=index.jsp");

        }else{
            response.getWriter().write("<h2><center>Failed! Return to the previous screen in three seconds!</center></h2>");
            //设置3秒钟跳转
            response.setHeader("refresh", "3;url=addItem.jsp");
        }

    }
}
(3)Select:
package Servlet;

import Dao.DaMaiI;
import entity.Item;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ItemSelectServlet", value = "/ItemSelectServlet")
public class ItemSelectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String id=request.getParameter("id");
        DaMaiI daMaiI = new DaMaiI();
        Item item= daMaiI.selectById(id);

        request.setAttribute("item",item);
        request.getRequestDispatcher("updateItem.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
(4)Delete:
package Servlet;

import Dao.DaMaiI;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ItemDeleteServlet", value = "/ItemDeleteServlet")
public class ItemDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String id=request.getParameter("id");
        DaMaiI daMaiI=new DaMaiI();
        if(daMaiI.deleteItem(id)){
            response.getWriter().write("<h2><center>Successful! Return to the previous screen in three seconds!</center></h2>");
            response.setHeader("refresh", "3;url=index.jsp");
        }else {
            response.getWriter().write("<h2><center>Failed!Return to the previous screen in three seconds!</h2></center>");
            response.setHeader("refresh", "3;url=index.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }


}
(5)Update:
package Servlet;

import Dao.DaMaiI;
import entity.Item;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ItemUpdateServlet", value = "/ItemUpdateServlet")
public class ItemUpdateServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");


        String img= request.getParameter("img");
        String id=request.getParameter("id");
        String address=request.getParameter("address");
        String price=request.getParameter("price");
        String time=request.getParameter("time");
        Item item = new Item(img,id,address,price,time);
        DaMaiI daMaiI = new DaMaiI();


        if(daMaiI.update(item)!=0){
            response.getWriter().write( "<h2><center>Successful! Return to the previous screen in three seconds!</center></h2>");
            response.setHeader("refresh", "3;url=index.jsp");

        }else {
            response.getWriter().write("<h2><center>Failed! Return to the previous screen in three seconds!</h2></center>");
            response.setHeader("refresh", "3;url=index.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }
}

  • 10
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值