2022年j课时十一——图书注册登录界面(Servlect对象)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 2022年j课时十一——图书注册登录界面(Servlect对象)

Servlect常用对象

ServlectConfig

ServlectContext

HttpServletResponse

HttpServlectRrquest

 1 构建上面的项目可以完成,图书界面的注册与登录

2 j进行图书界面的查看图书,购买图书,查看记录

代码编写

package com.Book.Servlect;
import java.io.IOException;
import java.io.PrintWriter;
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 com.entity.Book;
/**
 * Servlet implementation class AlertServlet
 */
@WebServlet("/AlertServlet")
public class AlertServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AlertServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    Book book=(Book) request.getAttribute("book");
    String info="<h1>当前《"+book.getBookName()+"书籍购买成功,如需需要再次购买请<a href='ShowBuyBookServlet'>点击这里</a>回到购书页面,"
        + "或者10秒之后自动跳转至首页</h1>";
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    //
    response.setHeader("refresh", "1"+"开始倒计时");
    //五秒后自动跳转到HomeServlet
    response.setHeader("refresh", "10;url=HomeServlet");
    PrintWriter pw=response.getWriter();
    pw.print(info);
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
package com.Book.Servlect;
import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContext;
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 com.entity.Book;
import com.util.BooksDBUtil;
/**
 * Servlet implementation class GetBuyBookInfoServlet
 */
@WebServlet("/GetBuyBookInfoServlet")
public class GetBuyBookInfoServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetBuyBookInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //获得浏览器发送的下标
    String index=request.getParameter("index");
    int i=Integer.parseInt(index);
    //根据下标从书库中定位到用户要购买的是哪本书
    List<Book> oBooks=BooksDBUtil.getBooks();
    Book book=oBooks.get(i);
    //获得当前购买的实时时间
    String time=BooksDBUtil.getNowTime();
    book.setBuyTime(time);
    //存储至ServletContext对象中
    ServletContext sc=getServletContext();
    //先判断ServletContext是否有其他的购买记录
    //如果有,新的购买记录只需要添加到原有的list集合里面
    //如果没有,现在是第一次买书,ServletContext之前没有保存过购买记录,也就意味着该对象中并不存在list集合
    Object object=sc.getAttribute("orders");
    List<Book> oList=null;
    if (object==null) {
      //说明从来都没有保存过购买记录
      oList=new ArrayList<Book>();
      oList.add(book);
    }else {
      //如果以前有保存过购买记录
      oList=(List<Book>) object;
      oList.add(book);
    }
    //将更新后的list集合保存至ServletContext对象
    sc.setAttribute("orders", oList);
    //跳转至一个Servlet页面,告诉用户当前购买成功,如需再次购买请点击这里回到购书页面
    //如果Servlet之间跳转不需要携带数据,传递数据,一般使用重定向
    //否则使用请求转发
    request.setAttribute("book", book);
    request.getRequestDispatcher("AlertServlet").forward(request, response);
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
package com.Book.Servlect;
/**
 * 浏览数据的主界面
 */
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class HomeServlet
 */
@WebServlet(urlPatterns = "/HomeServlet",initParams = {
    @WebInitParam(name="buyBook",value="购买图书"),
    @WebInitParam(name="selectOrder",value="查看记录"),
    //增加一个界面为手机管理
    @WebInitParam(name="buyBookA",value="购买图书A ")
})
public class HomeServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  String buyBook ="";
  String buyBookA ="";
  String  selectOrder="";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HomeServlet() {
        super();
        System.out.println("HomeServlet() 在运行主界面中");
        // TODO Auto-generated constructor stub
    }
    @Override
    public void init(ServletConfig config) throws ServletException {
      super.init(config);
      //得到二个静态数据
       buyBook =config.getInitParameter("buyBook");
       buyBookA =config.getInitParameter("buyBookA");
       selectOrder =config.getInitParameter("selectOrder");
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //当浏览器访问Servlet的组成浏览器能看到的页面
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter pw = response.getWriter();
    pw.append("<h1 align ='center'>图书界面</h1>");
    pw.append("<div align ='center'style=' background-color: #CCFFFF;'><h1 style='color:red'>");
    pw.append("<a href='ShowBuyBookServlet'>"+ buyBook+"</a>&nbsp;&nbsp;<br>");
    pw.append("<a href='ShowBuyBookServletA'>"+ buyBookA+"</a>&nbsp;&nbsp;<br>");
    pw.append("<a href='SelectOrderServlect'>"+selectOrder+"</a>&nbsp;&nbsp;<br>");
    pw.append("</h1></div>");
    System.out.println(buyBook+selectOrder);
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
package com.Book.Servlect;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletContext;
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 com.entity.Book;
/**
 * Servlet implementation class SelectOrderServlect
 */
@WebServlet("/SelectOrderServlect")
public class SelectOrderServlect extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SelectOrderServlect() {
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     //从servletContext对象中,获取购买图书,并把图书信息在表格中能看到
    ServletContext sc=getServletContext();
    Object object = sc.getAttribute("orders");
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter pw = response.getWriter();
    //进行判断 ifobject为null
    if(object==null) {
      pw.print("<h1 align ='center' style='color:red;font-size:30px'>查看记录</h1>");
      pw.print("<h1>当前没有购买读书信息请购买图书信息哦,五秒后跳到图书信息页面</h1>");
      response.sendRedirect(" response.sendRedirect('ShowBuyBookServlet');");
    }else {
      List<Book> oBooks=(List<Book>) object;
      pw.append("<div align='center'>");
      pw.append("<table border='3' style='width:800px;text-align:center;'>");
      pw.append("<tr>");
      pw.append("<td>书名</td>");
      pw.append("<td>作者</td>");
      pw.append("<td>单价</td>");
      pw.append("<td>出版社</td>");
      pw.append("<td>购买时间</td>");
      pw.append("</tr>");
      //根据循环遍历list集合,从list集合中获得每一本图书信息
      for (int i = 0; i < oBooks.size(); i++) {
        pw.append("<tr>");
        pw.append("<td style='  background-color: lavender'>"+oBooks.get(i).getBookName()+"</td>");
        pw.append("<td style='  background-color:  lightblue'>"+oBooks.get(i).getAutor()+"</td>");
        pw.append("<td style='  background-color: pink'>"+oBooks.get(i).getPrice()+"</td>");
        pw.append("<td style='  background-color:  lightblue'>"+oBooks.get(i).getAddress()+"</td>");
        pw.append("<td>"+oBooks.get(i).getBuyTime()+"</td>");
        pw.append("</tr>");
      }
      pw.append("</table>");
      pw.append("</div>");
    }
    }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
package com.Book.Servlect;
import java.io.IOException;
import java.io.PrintWriter;
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 com.entity.Book;
import com.util.BooksDBUtil;
/**
 * Servlet implementation class ShowBuyBookServlet
 */
@WebServlet("/ShowBuyBookServlet")
public class ShowBuyBookServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowBuyBookServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //从其他类中获取出要显示在浏览器上的所有图书信息
    List<Book> oBooks=BooksDBUtil.getBooks();
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    PrintWriter pw=response.getWriter();
    pw.append("<h1 align ='center' style='color:red'>手机浏览界面</h1>");
    pw.append("<div align='center'>");
    pw.append("<table border='3' style='width:800px;text-align:center;'>");
    pw.append("<tr>");
    pw.append("<td>书名</td>");
    pw.append("<td>作者 </td>");
    pw.append("<td>单价</td>");
    pw.append("<td>出版社</td>");
    pw.append("<td>操作</td>");
    pw.append("</tr>");
    //根据循环遍历list集合,从list集合中获得每一本图书信息
    for (int i = 0; i < oBooks.size(); i++) {
      pw.append("<tr>");
      pw.append("<td style='  background-color: lavender'>"+oBooks.get(i).getBookName()+"</td>");
      pw.append("<td style='  background-color:  lightblue'>"+oBooks.get(i).getAutor()+"</td>");
      pw.append("<td style='  background-color: pink'>"+oBooks.get(i).getPrice()+"</td>");
      pw.append("<td style='  background-color:  lightblue'>"+oBooks.get(i).getAddress()+"</td>");
      pw.append("<td style='  background-color: yellow'><a href='GetBuyBookInfoServlet?index="+i+"'>"
          + "<input type='button' value='购买' style='background: lightblue;width:100px'></a></td>");
      pw.append("</tr>");
    }
    pw.append("</table>");
    pw.append("</div>");
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
package com.Book.Servlect;
import java.io.IOException;
import java.io.PrintWriter;
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 com.entity.Book;
import com.util.BooksDBUtil;
import com.util.BooksDBUtilA;
/**
 * Servlet implementation class ShowBuyBookServlet
 */
@WebServlet("/ShowBuyBookServletA")
public class ShowBuyBookServletA extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowBuyBookServletA() {
        super();
        // TODO Auto-generated constructor stub
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //从其他类中获取出要显示在浏览器上的所有图书信息
    List<Book> oBooks=BooksDBUtilA.getBooks();
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    PrintWriter pw=response.getWriter();
    pw.append("<h1 align ='center' style='color:red'>手机浏览界面</h1>");
    pw.append("<div align='center'>");
    pw.append("<table border='3' style='width:800px;text-align:center;'>");
    pw.append("<tr>");
    pw.append("<td>书名</td>");
    pw.append("<td>作者 </td>");
    pw.append("<td>单价</td>");
    pw.append("<td>出版社</td>");
    pw.append("<td>操作</td>");
    pw.append("</tr>");
    //根据循环遍历list集合,从list集合中获得每一本图书信息
    for (int i = 0; i < oBooks.size(); i++) {
      pw.append("<tr>");
      pw.append("<td style='  background-color: lavender'>"+oBooks.get(i).getBookName()+"</td>");
      pw.append("<td style='  background-color:  lightblue'>"+oBooks.get(i).getAutor()+"</td>");
      pw.append("<td style='  background-color: pink'>"+oBooks.get(i).getPrice()+"</td>");
      pw.append("<td style='  background-color:  lightblue'>"+oBooks.get(i).getAddress()+"</td>");
      pw.append("<td style='  background-color: yellow'><a href='GetBuyBookInfoServlet?index="+i+"'>"
          + "<input type='button' value='购买' style='background: lightblue;width:100px'></a></td>");
      pw.append("</tr>");
    }
    pw.append("</table>");
    pw.append("</div>");
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
package com.DengLu.And.Zhu.Ce;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class ServlectDengLu
 */
@WebServlet("/ServlectDengLu")
public class ServlectDengLu extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServlectDengLu() {
        super();
        System.out.println("欢迎来到登陆界面哦");
        // TODO Auto-generated constructor stub
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter pw = response.getWriter();
    pw.append("<h1 align ='center'>图书BookReading登陆界面</h1>");
    pw.append("<div  align ='center' style='color':'pink'>");
    pw.append("<form action='ServlectDengLuLogic' method='post'>");
    pw.append("<h1 align ='center' style='color:red'>欢迎来到登陆界面</h1>");
    pw.append("用户名:<input type='text' name='use'>"
        + "<br>");
    pw.append("用户新密码:<input type='password' name='pw'>"
        + "<br>");
    pw.append("请再次输入新密码:<input type='password' name='pws'"
        + "<br>"+"<br>" );  
    pw.append("<input type='submit' value='登陆'>");
    pw.append("</form>");
    pw.append("</div>");
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  }
}
package com.DengLu.And.Zhu.Ce;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class ServlectDengLuLogic
 */
@WebServlet("/ServlectDengLuLogic")
public class ServlectDengLuLogic extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServlectDengLuLogic() {
        super();
        // TODO Auto-generated constructor stub
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.getWriter().append("Served at: ").append(request.getContextPath());
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    /**
     * do--post
     */
     response.setContentType("text/html");
     response.setCharacterEncoding("UTF-8");
    ServletContext  sc=getServletContext();
    //获取web.xml文件中的镜头数据
    String a=sc.getInitParameter("uses");
    String b=sc.getInitParameter("PW");
    String c=sc.getInitParameter("PWS");
    System.out.println(a+"@@@@@@@@"+b+"######"+c);
     response.getWriter().append("ServletB获得静态数据用来访问web.xml"+a);
     String aa=request.getParameter("use");
     String bb=request.getParameter("pw");
     String cc=request.getParameter("pws");
      System.out.println(aa+":"+bb+":"+cc);
      //不区分大小写equalsIgnoreCase(aa)
      if(a.equalsIgnoreCase(aa)&&b.equalsIgnoreCase(bb)&&c.equalsIgnoreCase(cc)) {
        //重定向跳转页面
        System.out.println("登录成功跳转到图书界面");
        response.sendRedirect("HomeServlet");
      }else {
        System.out.println("登录失败五秒后返回ServlectDengLuLose");
        response.sendRedirect("ServlectDengLuLose");
      }
  }
}
package com.DengLu.And.Zhu.Ce;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class ServlectDengLuLose
 */
@WebServlet("/ServlectDengLuLose")
public class ServlectDengLuLose extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServlectDengLuLose() {
        super();
        // TODO Auto-generated constructor stub
    }
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter pw = response.getWriter();
    pw.append("<h1 align ='center'>BookReading登陆失败的界面</h1>");
    pw.append("登陆界面失败请重新登陆");
    response.setHeader("refresh","5;URL=ServlectDengLu");
    pw.append("<h2 align ='center'><a href='ServlectDengLu'>点击这里返回登陆界面进行重新登陆</a></h2>");
    pw.append("如果用户一分钟后没有任何操作则在60秒后调到index.jsp文件");
    response.setHeader("refresh","60;URL=insex.jsp");
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
package com.entity;
/**
 * 
 * 图书实体类
 * @author MZFAITHDREAM
 * 2021/10/19
 *
 */
public class Book {
   private String bookName;  //书名
   private  String autor;   //作者
   private  String price;
   private  String address;//出版社
   private  String buyTime;   //图书时间
  //生成get set方法
  //null构造方法 创建对象 在创建对象
   //toString
  public Book() {
    // TODO Auto-generated constructor stub
  }
  public Book(String bookName, String autor, String price, String address, String buyTime) {
    super();
    this.bookName = bookName;
    this.autor = autor;
    this.price = price;
    this.address = address;
    this.buyTime = buyTime;
  }
  public String getBookName() {
    return bookName;
  }
  public void setBookName(String bookName) {
    this.bookName = bookName;
  }
  public String getAutor() {
    return autor;
  }
  public void setAutor(String autor) {
    this.autor = autor;
  }
  public String getPrice() {
    return price;
  }
  public void setPrice(String price) {
    this.price = price;
  }
  public String getAddress() {
    return address;
  }
  public void setAddress(String address) {
    this.address = address;
  }
  public String getBuyTime() {
    return buyTime;
  }
  public void setBuyTime(String buyTime) {
    this.buyTime = buyTime;
  }
  @Override
  public String toString() {
    return "Book [bookName=" + bookName + ", autor=" + autor + ", price=" + price + ", address=" + address
        + ", buyTime=" + buyTime + "]";
  }
package com.entity;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * 定义手机名称  手机型号 手机的色彩    价格
 * @author MZFAITHDREAM
 *定义一个标准类
 */
public class phone {
  private String pname;//手机名称
  private String pmodel;
  private String color;
  private String price;
  private String land; //手机厚度
  public phone() {
    // TODO Auto-generated constructor stub
  }
  public phone(String pname, String pmodel, String color, String price, String land) {
    super();
    this.pname = pname;
    this.pmodel = pmodel;
    this.color = color;
    this.price = price;
    this.land = land;
  }
  public String getPname() {
    return pname;
  }
  public void setPname(String pname) {
    this.pname = pname;
  }
  public String getPmodel() {
    return pmodel;
  }
  public void setPmodel(String pmodel) {
    this.pmodel = pmodel;
  }
  public String getColor() {
    return color;
  }
  public void setColor(String color) {
    this.color = color;
  }
  public String getPrice() {
    return price;
  }
  public void setPrice(String price) {
    this.price = price;
  }
  public String getLand() {
    return land;
  }
  public void setLand(String land) {
    this.land = land;
  }
  @Override
  public String toString() {
    return "phone [pname=" + pname + ", pmodel=" + pmodel + ", color=" + color + ", price=" + price + ", land="
        + land + "]";
  }
  public String getTime() {
    // TODO Auto-generated method stub
    Date date=new Date();
    //2021年10月19日
    SimpleDateFormat sdf=new SimpleDateFormat ("YYYY年MM月DD日HH:mm:ss");
    //要求当前时间进行格式化
    String time=sdf.format(date);
    return null;
  }
  public void setBuyTime(String time) {
    // TODO Auto-generated method stub
    //2021年10月19日
  }
}
package com.util;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.entity.Book;
/**
 * 放图书的内容工具类
 * @author MZFAITHDREAM
 *2021/10/19
 */
public class BooksDBUtil {
  public static List<Book> getBooks(){
    Book book1 =new Book("java程序设计","自由", "39元","人民日报","");
    Book book2 =new Book("java网站设计","马玉", "89元","清华","");
    Book book3 =new Book("javascript程序设计","不变", "239元","人民日报","");
    Book book4 =new Book("jquery程序设计","胡毅", "189元","江西出版社","");
    Book book5=new Book("mysql程序设计","ok", "179元","北大","");
    Book book6 =new Book("Sping框架设计","胡三", "129元","人民日报","");
    Book book7 =new Book("java高级编程","呼万岁", "159元","河南出版社","");
    Book book8=new Book("ps设计","ok", "239元","西安出版社","");
    Book book9 =new Book("Sping框架设计","胡三", "129元","人民日报","");
    Book book10=new Book("Java程序设计", "马云", "78.0元", "人民邮电出版社", "");
    Book book11=new Book("Jsp网络编程", "马化腾", "118.0元", "清华大学出版社", "");
    Book book12=new Book("Python爬虫技术", "李彦宏", "65.0元", "电子工业出版社", "");
    Book book13=new Book("网页程序设计", "任正非", "38.0元", "江西出版社", "");
    Book book14=new Book("MySQL程序教程", "雷军", "59.0元", "吉林出版社", "");
    Book book15=new Book("Spring框架技术", "马小云", "46.0元", "人民邮电出版社", "");
    List <Book> oBooks=new ArrayList<Book>();
    oBooks.add(book1);
    oBooks.add(book2);
    oBooks.add(book3);
    oBooks.add(book4);
    oBooks.add(book5);
    oBooks.add(book6);
    oBooks.add(book7);
    oBooks.add(book8);
    oBooks.add(book9);
    oBooks.add(book10);
    oBooks.add(book11);
    oBooks.add(book12);
    oBooks.add(book13);
    oBooks.add(book14);
    oBooks.add(book15);
    return oBooks;
  }
  public static String getNowTime() {
    Date date=new Date();
    //2021年10月19日
    SimpleDateFormat sdf=new SimpleDateFormat ("YYYY年MM月DD日HH:mm:ss");
    //要求当前时间进行格式化
    String time=sdf.format(date);
    return time;
  }
}
package com.util;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.entity.Book;
/**
 * 放图书的内容工具类
 * @author MZFAITHDREAM
 *2021/10/19
 */
public class BooksDBUtilA {
  public static List<Book> getBooks(){
    Book book1 =new Book("java基础","自由", "39元","人民日报","");
    Book book2 =new Book("html网站设计","马玉", "489元","清华","");
    Book book3 =new Book("javascript程序设计","不变", "239元","人民日报","");
    Book book4 =new Book("jquery程序设计","胡毅", "189元","江西出版社","");
    Book book5=new Book("mysql程序设计","ok", "179元","北大","");
    Book book6 =new Book("Sping框架设计","胡三", "129元","人民日报","");
    Book book7 =new Book("java高级编程","呼万岁", "159元","河南出版社","");
    Book book8=new Book("ps设计","ok", "239元","西安出版社","");
    Book book9 =new Book("Sping框架设计","胡三", "129元","人民日报","");
    Book book10=new Book("Java程序设计", "马云", "78.0元", "人民邮电出版社", "");
    Book book11=new Book("Jsp网络编程", "马化腾", "118.0元", "清华大学出版社", "");
    Book book12=new Book("Python爬虫技术", "李彦宏", "65.0元", "电子工业出版社", "");
    Book book13=new Book("网页程序设计", "任正非", "38.0元", "江西出版社", "");
    Book book14=new Book("MySQL程序教程", "雷军", "59.0元", "吉林出版社", "");
    Book book15=new Book("Spring框架技术", "马小云", "46.0元", "人民邮电出版社", "");
    List <Book> oBooks=new ArrayList<Book>();
    oBooks.add(book1);
    oBooks.add(book2);
    oBooks.add(book3);
    oBooks.add(book4);
    oBooks.add(book5);
    oBooks.add(book6);
    oBooks.add(book7);
    oBooks.add(book8);
    oBooks.add(book9);
    oBooks.add(book10);
    oBooks.add(book11);
    oBooks.add(book12);
    oBooks.add(book13);
    oBooks.add(book14);
    oBooks.add(book15);
    return oBooks;
  }
  public static String getNowTime() {
    Date date=new Date();
    //2021年10月19日
    SimpleDateFormat sdf=new SimpleDateFormat ("YYYY年MM月DD日HH:mm:ss");
    //要求当前时间进行格式化
    String time=sdf.format(date);
    return time;
  }
}
package com.util;
import java.sql.Connection;
public class Time {
  public static int time=60*60*60;
  static Connection time() {
    while (time>0) {
      time--;
      try {
        Thread.sleep(1000);
        int hh=time/1/1%1;
        int mm=time/60%1;
        int ss=time%6;
        if(hh==0 &&mm==0 && ss==0) {
          break;
        }
        System.out.println("0小时"+hh+"Сʱ"+mm+"分钟"+ss+"秒");
      } catch (InterruptedException e) {
        // TODO: handle exception
    }finally {
      System.out.println("正在跳转页面哦 ServlectB");
      System.out.println(".......真在跳转页面 ");
    }
    }
    return null;
  }
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    time();
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>BookReading</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>
  <context-param>
  <param-name>uses</param-name>
  <param-value>hug</param-value>
  </context-param>
  <context-param>
  <param-name>phone</param-name>
  <param-value>18172928419</param-value>
  </context-param>
  <context-param>
  <param-name>YM</param-name>
  <param-value>666666</param-value>
  </context-param>
  <context-param>
  <param-name>PW</param-name>
  <param-value>123456</param-value>
  </context-param>
  <context-param>
  <param-name>PWS</param-name>
  <param-value>123456</param-value>
  </context-param>
</web-app>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BookReading-JSP</title>
</head>
<body>
<h1 style="color: red ;background: yellow;">欢迎来到BookReading管理系统的主界面</h1>
<hr>
<a href="ServlectZhuZeA" style="color:brown;font-size: 26px">点击这里进入注册界面哦</a>
</body>
</html>

Servlect真奇妙


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
8月前
|
Java 数据库连接 数据库
SSM详细整合(有登录注册的例子)
SSM详细整合(有登录注册的例子)
52 2
|
前端开发 JavaScript Java
Layui的入门级教学,基本使用及如何实现登入与注册页面
Layui的入门级教学,基本使用及如何实现登入与注册页面
418 0
|
7月前
|
SQL druid Java
javaweb案例实训之基于jsp和servlet的用户管理开发[增删改查及登录注销]
javaweb案例实训之基于jsp和servlet的用户管理开发[增删改查及登录注销]
53 0
|
8月前
当当网新用户注册界面——界面源码
当当网新用户注册界面——界面源码
|
SQL Java 关系型数据库
JSP图书销售系统myeclipse开发sql数据库BS模式java编程
JSP 图书销售系统是一套完善的web设计系统,对理解JSP java编程开发语言有帮助系统具有完整的源代码和数据库,系统主要采用B/S模式开发。
73 0
|
存储 数据安全/隐私保护 开发者
小白必看系列之图书管理系统-登录和注册功能示例代码
小白必看系列之图书管理系统-登录和注册功能示例代码
166 1
|
存储 前端开发 Java
【JavaWeb】JAVABean+Session实现JSP登录注册(List模型数据库用户信息存储+商品展示)
先说说这个题目吧,好端端的数据库不连,偏偏喜欢要整一个JavaBean和List来模拟数据库,虽然说这样的做法非常的愚蠢,但没办法,毕竟是主人的任务是吧doge。作者其实已经做了一版,但是这代码写的实在是。。。于是乎作者使用了MVC框架后整理了一个新的。(如果你学了servlet,那会发现和它的结构和思想非常的像)
126 0
|
编解码 Java
SpringBoot日记本系统 :详情页-日记类型显示码值问题 解决
SpringBoot日记本系统 :详情页-日记类型显示码值问题 解决
|
Java
2022年Jsp课程课时八——案例(Servlect常用对象)
2022年Jsp课程课时八——案例(Servlect常用对象)
77 0
2022年Jsp课程课时八——案例(Servlect常用对象)
|
JSON 前端开发 JavaScript
课程管理-修改课程信息(前端)| 学习笔记
简介:快速学习课程管理-修改课程信息(前端)
280 0
课程管理-修改课程信息(前端)| 学习笔记

热门文章

最新文章