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 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦