使用JSP+SERVLET+JDBC实现对数据库的增删改查 下载本文

} if(rs!=null){ rs.close(); } close(stat,conn); return result; }

//条件查询跳转

public void dispatch(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, ServletException, IOException{ String id5=request.getParameter(\ String name5=request.getParameter(\ if(select(id5,name5).isEmpty()){ request.getRequestDispatcher(\ } else{ request.setAttribute(\

request.getRequestDispatcher(\ } }

//设置分页相关参数方法 public Page setpage(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException{ String crd=request.getParameter(\ //String id=request.getParameter(\

// String name=request.getParameter(\ ArrayList result=select(\ Page pager=new Page(); pager.setTotalRecord(result.size()); pager.setTotalPage(result.size(),pager.getPageSize()); if(crd!=null) { int currentRecord=Integer.parseInt(crd); pager.setCurrentRecord(currentRecord);

pager.setCurrentPage(currentRecord,pager.getPageSize()); } return pager; } //获得分页显示的子集 public void difpage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException{ // String id=request.getParameter(\ // String name=request.getParameter(\ ArrayList result=select(\

Page pager=new Page(); pager=setpage(request,response); List subResult=null;

int currentRecord=pager.getCurrentRecord(); if(currentRecord==0){

if(pager.getTotalRecord()<8){ subResult=(List) result.subList(0,pager.getTotalRecord()); } else{ subResult=(List) result.subList(0,pager.getPageSize()); } }

else if(pager.getCurrentRecord()+pager.getPageSize()

subResult=(List)

result.subList(pager.getCurrentRecord(),pager.getCurrentRecord()+pager.getPageSize()); } else {

subResult=(List) result.subList(pager.getCurrentRecord(),result.size()); }

request.setAttribute(\ request.setAttribute(\ request.getRequestDispatcher(\ }

//信息删除方法

public void delete(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, ServletException, IOException{ Connection conn=null; Statement stat=null; conn=connect(); stat=conn.createStatement(); String id2=request.getParameter(\ stat.execute(\ request.getRequestDispatcher(\ }

//信息修改方法

public void update1(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, ServletException, IOException{ String id4=request.getParameter(\ request.setAttribute(\

request.getRequestDispatcher(\ }

public void update(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, ServletException, IOException{ Connection conn=null; Statement stat=null;

String id3=request.getParameter(\

String name3=request.getParameter(\ String age3=request.getParameter(\

String gender3=request.getParameter(\ String major3=request.getParameter(\ conn=connect(); stat=conn.createStatement(); stat.execute(\student set id=\where id=\ request.setAttribute(\ request.getRequestDispatcher(\ } }

10,在webRoot目录下添加以下.jsp文件 10.1 putin.jsp

<%@ page language=\<%

String path = request.getContextPath(); String basePath = request.getScheme()+\%>

学生信息输入


学生信息输入


学号:

姓名: 年龄: 性别: