为了账号安全,请及时绑定邮箱和手机立即绑定

JSP+Servlet+mysql 添加书籍入库

标签:
Java
jsp:
<form action="/Test06/AddbookServlet" method="post">
图数名:<input type="text" name="bookname"><br/>
作者:<input type="text" name="author"><br/>
价格:<input type="text" name="price"><br/>
图书类型:<input type="text" name="booktype"><br/>
出版社:<input type="text" name="publishing"><br/>
图书本数:<input type="text" name="booksum"><br/>
<input type="submit" value="添加">
</form>
Servlet:
String bn=new String(request.getParameter("bookname"));
  String at=new String(request.getParameter("author"));
  String pc=new String(request.getParameter("price"));
  String bt=new String(request.getParameter("booktype"));
  String ps=new String(request.getParameter("publishing"));
  int bs=Integer.parseInt(request.getParameter("booksum"));
  
  Book book = new Book();
  book.setBookname(bn);
  book.setAuthor(at);
  book.setPrice(pc);
  book.setBooktype(bt);
  book.setPublishing(ps);
  book.setBooksum(bs);
  BookDao bookdao=new BookDao();
  bookdao.addBook(book);

这是增加书籍功能

第一段代码是提交一个form表单,这个表单对应的请求地址/Test06/AddbookServlet是这个,通过前台也是jsp显示的页面的表单提交按钮,调到对应的servlet

Servlet收到jsp的请求之后通过request.getParameter拿到前台对应的标签值,也是 name参数的value值,比如bookname  

把页面想添加的书本名字通过book对象传递  来设置到封装类对应的书名 也就是通过面向对象的思想,将其值放入到book对象中, 

在调用数据库访问对象中添加数据到数据库的功能就是调用dao层,让jsp 页面的数据入库。

 

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消