- 浏览: 15904 次
- 性别:
最新评论
接着上次的
DAO层
删除操作
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javax.swing.DefaultBoundedRangeModel;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.dao.BookDao;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class DeleteBookServlet
*/
public class DeleteBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String sn=request.getParameter("sn");
DBUtil dbUtil=new DefaultDBUtil();
try{
Connection conn=dbUtil.openConn();
BussinessService b=new BussinessServiceImpl(conn);
b.deletebook(sn, conn);
List<Book>books=b.showallbooks();
request.setAttribute("book", books);
request.setAttribute("flag", sn);
request.getRequestDispatcher("booklist.jsp").forward(request, response);
}finally{
dbUtil.closeConn();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
改
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class EditBookServlet
*/
public class EditBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
DBUtil dbUtil=new DefaultDBUtil();
try{
Connection conn=dbUtil.openConn();
BussinessService service=new BussinessServiceImpl(conn);
List<Book>listbook=service.showallbooks();
request.setAttribute("book", listbook);
request.getRequestDispatcher("editBook.jsp").forward(request, response);
}finally{
dbUtil.closeConn();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
先把数据set到jsp中,再得到参数
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class SureEdit
*/
public class SureEdit extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
DBUtil dbUtil=new DefaultDBUtil();
Connection conn=dbUtil.openConn();
String sn=request.getParameter("sn");
String name=request.getParameter("name");
BussinessService service=new BussinessServiceImpl(conn);
try{
service.updatebook(sn, name, conn);
List<Book>listBooks=service.showallbooks();
request.setAttribute("book", listBooks);
request.getRequestDispatcher("booklist.jsp").forward(request, response);
}
finally{
dbUtil.closeConn();
}
}
}
<%@page import="java.util.List"%>
<%@page import="com.zhouxiaobo.demo.jdbc.bean.Book"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<table border="1" cellspacing="0" cellpadding="0 width="100%" style="align:center;">
<tr bgcolor="CCC000" style="font-weight:bold;">
<c:forEach var="bk" items="${book}">
<tr>
<form action="/LIB/sureEdit" method="post">
书号<input type="text" name="sn" value="${bk.sn}">
书名<input type="text" name="name" value="${bk.name}">
<input type="submit" value="更改"><br>
</form>
</c:forEach>
</table>
查
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class Findbysn
*/
public class Findbysn extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
DBUtil dbUtil=new DefaultDBUtil();
try{
Connection conn=dbUtil.openConn();
String sn=request.getParameter("sn");
BussinessService service=new BussinessServiceImpl(conn);
List<Book> books=service.findbysn(sn, conn);
request.setAttribute("book", books);
request.getRequestDispatcher("booklist.jsp").forward(request, response);
}finally{
dbUtil.closeConn();
}
}
}
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>Insert title here</title>
</head>
<body>
<form action="/LIB/findbysn" method="post">
书号<input type="text" name="sn"><br>
<input type="submit" value="查找"><br>
<input type="hidden" name="kind" value="insert"><br>
</form>
</body>
</html>
DAO层
删除操作
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
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 javax.swing.DefaultBoundedRangeModel;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.dao.BookDao;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class DeleteBookServlet
*/
public class DeleteBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String sn=request.getParameter("sn");
DBUtil dbUtil=new DefaultDBUtil();
try{
Connection conn=dbUtil.openConn();
BussinessService b=new BussinessServiceImpl(conn);
b.deletebook(sn, conn);
List<Book>books=b.showallbooks();
request.setAttribute("book", books);
request.setAttribute("flag", sn);
request.getRequestDispatcher("booklist.jsp").forward(request, response);
}finally{
dbUtil.closeConn();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
改
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class EditBookServlet
*/
public class EditBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
DBUtil dbUtil=new DefaultDBUtil();
try{
Connection conn=dbUtil.openConn();
BussinessService service=new BussinessServiceImpl(conn);
List<Book>listbook=service.showallbooks();
request.setAttribute("book", listbook);
request.getRequestDispatcher("editBook.jsp").forward(request, response);
}finally{
dbUtil.closeConn();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
先把数据set到jsp中,再得到参数
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class SureEdit
*/
public class SureEdit extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
DBUtil dbUtil=new DefaultDBUtil();
Connection conn=dbUtil.openConn();
String sn=request.getParameter("sn");
String name=request.getParameter("name");
BussinessService service=new BussinessServiceImpl(conn);
try{
service.updatebook(sn, name, conn);
List<Book>listBooks=service.showallbooks();
request.setAttribute("book", listBooks);
request.getRequestDispatcher("booklist.jsp").forward(request, response);
}
finally{
dbUtil.closeConn();
}
}
}
<%@page import="java.util.List"%>
<%@page import="com.zhouxiaobo.demo.jdbc.bean.Book"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<table border="1" cellspacing="0" cellpadding="0 width="100%" style="align:center;">
<tr bgcolor="CCC000" style="font-weight:bold;">
<c:forEach var="bk" items="${book}">
<tr>
<form action="/LIB/sureEdit" method="post">
书号<input type="text" name="sn" value="${bk.sn}">
书名<input type="text" name="name" value="${bk.name}">
<input type="submit" value="更改"><br>
</form>
</c:forEach>
</table>
查
package com.zhouxiaobo.demo;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhouxiaobo.demo.jdbc.bean.Book;
import com.zhouxiaobo.demo.jdbc.service.BussinessService;
import com.zhouxiaobo.demo.jdbc.service.BussinessServiceImpl;
import com.zhouxiaobo.demo.jdbc.util.DBUtil;
import com.zhouxiaobo.demo.jdbc.util.DefaultDBUtil;
/**
* Servlet implementation class Findbysn
*/
public class Findbysn extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
DBUtil dbUtil=new DefaultDBUtil();
try{
Connection conn=dbUtil.openConn();
String sn=request.getParameter("sn");
BussinessService service=new BussinessServiceImpl(conn);
List<Book> books=service.findbysn(sn, conn);
request.setAttribute("book", books);
request.getRequestDispatcher("booklist.jsp").forward(request, response);
}finally{
dbUtil.closeConn();
}
}
}
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>Insert title here</title>
</head>
<body>
<form action="/LIB/findbysn" method="post">
书号<input type="text" name="sn"><br>
<input type="submit" value="查找"><br>
<input type="hidden" name="kind" value="insert"><br>
</form>
</body>
</html>
发表评论
-
删除<作废>
2015-05-03 15:54 485<table class="tbl-box& ... -
excel转换成JAVA到Mysql
2015-04-29 13:43 619excel转换成JAVA到Mysql -
第一个项目的jsp<不会的很多啊!!!>
2015-04-27 18:27 807<%@ page language="java ... -
/*发送短信*/
2015-04-27 18:23 351/*发送邮件*/ $("#sendEma ... -
jquery 删除
2015-04-26 18:32 415$("#btn_clear").click ... -
省市区
2015-04-27 18:23 541<script> $(function(){ ... -
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
2015-04-26 13:16 896<%@ taglib uri="http:// ... -
sql
2015-04-24 20:24 759<?xml version="1.0" ... -
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
2015-04-24 14:43 1649<%@ taglib prefix="spri ... -
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2015-04-24 14:44 960<%@ taglib prefix="c&qu ... -
<%@ taglib prefix="code" uri="/WEB-INF/tld/code4dropdown.tld"%>
2015-04-24 14:44 640<%@ taglib prefix="code ... -
Android工具下载
2015-04-24 14:44 421原文:http://blog.csdn.net/shulian ... -
mybatis的配置
2015-04-08 16:49 533jdbc.properties driver=com.my ... -
mybatis
2015-04-08 16:45 448pom <project xmlns="htt ... -
JAVA入门简单的增删改查(Servlet+JSP)一
2015-04-08 16:20 2553是一个图书的增删改查 JDBC的连接 package com. ...
相关推荐
技术栈 Servlet + Jsp + Tomcat , 是Java Web入门非常好的练手项目.zip 技术栈 Servlet + Jsp + Tomcat , 是Java Web入门非常好的练手项目.zip 技术栈 Servlet + Jsp + Tomcat , 是Java Web入门非常好的练手项目.zip...
在IT行业中,Web开发是一项核心技能,而"jsp+servlet+mysql+tomcat实现增删改查"是初学者常见的入门实践项目。这个项目旨在帮助新手掌握基于Java Web的动态网站开发技术,通过Eclipse这样的集成开发环境(IDE)进行...
Java入门练手项目, 基于 Servlet + Jsp + Tomcat
总的来说,Java Servlet+JDBC的增删改查涵盖了Web开发的基本流程,是学习Java Web的入门基础。理解并熟练掌握这些知识点,可以为后续的Web框架学习(如Spring Boot、Struts、JSF等)打下坚实的基础。在实际开发中,...
总之,"Servlet+jsp注册登录增删改查万能模板"是一个全面的Java Web学习资源,涵盖了Web开发的基本元素,适合初学者入门和实践,同时也为更高级的项目开发奠定了基础。通过深入学习和实践,可以掌握Java Web开发的...
Java入门教程:基于JDBC、Servlet和JSP的增删改查操作 在Java开发领域,Web应用程序的构建是常用的任务之一,而增删改查(CRUD)操作是任何数据库驱动应用的基础。本教程将重点讲解如何使用Java标准库JDBC、Servlet...
项目名称:基于JSP+Servlet+Mysql的宠物管理系统(简单增删改查) 项目架构:B/S架构 开发语言:Java语言 后端技术:JSP、Servlet、JDBC等技术 运行环境:Win10、JDK1.8 数 据 库:MySQL5.7及以上 运行服务器:...
项目名称:基于JSP+Servlet+Mysql的学生宿舍管理系统(简单的增删改查) 项目架构:B/S架构 开发语言:Java语言 后端技术:JSP、Servlet、JDBC等技术 运行环境:Win10、JDK1.8 数 据 库:MySQL5.7及以上 运行...
本项目是一个基于JSP、Servlet和JDBC技术的简单注册登录系统,旨在帮助初学者快速理解和掌握这些核心技术在实际开发中的应用。在这个项目中,开发者将使用MySQL作为后端数据库,创建一个名为`test`的数据库,并在...
一个使用jsp+servlet+mysql开发简单宠物管理系统,功能如下: 包含宠物的按分类查询,添加宠物、编辑...原来没有编辑、删除功能,在基础上做了升级,使之成为了一个完成的增删改查模块,功能比较简单,适合小白入门。
基于javaBean+jsp+servlet+mysql开发的模拟百度网盘的个人网盘系统源码(课程作业).zip基于javaBean+jsp+servlet+mysql开发的模拟百度网盘的个人网盘系统源码(课程作业).zip基于javaBean+jsp+servlet+mysql开发的模拟...
宿舍管理系统-jsp+servlet+mysql宿舍管理系统-jsp+servlet+mysql宿舍管理系统-jsp+servlet+mysql宿舍管理系统-jsp+servlet+mysql宿舍管理系统-jsp+servlet+mysql宿舍管理系统-jsp+servlet+mysql宿舍管理系统-jsp+...
### JAVA+JSP+Servlet+Android+SSH视频教程全集+项目视频知识点解析 #### Java基础知识及应用 Java作为一门跨平台的高级编程语言,在软件开发领域占据着重要的地位。本教程将涵盖Java基础语法、面向对象编程(OOP)...
本项目是一个SSM入门实例,主要展示了如何使用这三个框架进行基本的增删改查操作,并结合数据库进行数据操作。 1. **Spring框架**:Spring是Java企业级应用的核心,提供了一个容器来管理对象(如Bean)的生命周期和...
项目名称:基于JSP+Servlet+Mysql的宠物管理系统(简单增删改查) 项目架构:B/S架构 开发语言:Java语言 后端技术:JSP、Servlet、JDBC等技术 运行环境:Win10、JDK1.8 数 据 库:MySQL5.7及以上 运行服务器:...
以前不知道哪里找到的一个系统,感觉很不错,使用文档,数据库文件,项目截图全都包括,后台使用Servlet+Jsp,前台用的H-ui+EasyUI+jQuery,很适合新手入门的学习,特别是代码里面许许多多的注释,让我受益匪浅,...
适合刚刚入门javaweb学习的菜鸟 1.jdbc(baseDao+UserDao) 2.servlet 3.entity 注明: 1.jdbc:jdbc很详细(从头到尾的步骤)(适合jdbc基础不是很好的人群参考) 2.所用到的jar包(jstl+standard+mysql-connector-java-...
基于servlet、jsp简单的增删改查询,运用反射创建了一个微型的框架,页面借助了bootstrap、jquery这些成熟的前端框架,本来是帮同学写的作业,快一年没接触Java了,在同学的请求下练练了手,可以做Java入门参考,...
【标题】"jsp+JavaBean+Servlet+MySQL宿舍管理系统(初学者)"是一个针对初学者设计的项目,旨在帮助他们理解并实践Web应用开发的基本技术。这个系统的核心是使用JSP(JavaServer Pages)来展示界面,JavaBean作为业务...
《Java Web整合开发王者归来(JSP+Servlet+Struts+Hibernate+Spring)》全面介绍了Java Web开发中的各种相关技术及知识。全书分为9篇,内容层次清晰,难度循序渐进。第1篇为入门篇,内容包括Java Web开发概述等;第2篇...