运用MVC对数据进行一些简单的处理,基本实现数据的增删改查,达到前端和后台的数据之间的交互。

1.开始界面

  1. <%@page import="com.zdsofe.work.Student"%>
  2. <%@page import="java.util.List"%>
  3. <%@page import="com.zdsofe.work.ReadData"%>
  4. <%@ page language="java" contentType="text/html; charset=UTF-8"
  5. pageEncoding="UTF-8"%>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Insert title here</title>
  11. <script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
  12. <script type="text/javascript">
  13. function fun1() {
  14. $(":checkbox").attr("checked","checked");
  15. }
  16.  
  17. function fun2() {
  18. $(":checkbox").attr("checked",false);
  19. }
  20.  
  21. </script>
  22. </head>
  23. <body>
  24. <% ReadData rd=new ReadData();
  25. List<Student> list= rd.findInfo();
  26.  
  27. %>
  28. <form action="../MoreDeleteServlet" >
  29. <table border="1">
  30. <tr> <td colspan="4"><button type="button" onclick="fun1()">全选</button>
  31. <button type="button" onclick="fun2()">全不选</button></td></tr>
  32. <tr>
  33. <th>序号</th>
  34. <th>名字</th>
  35. <th>密码</th>
  36. <th>操作</th>
  37. </tr>
  38.  
  39. <%
  40. for(int i=0;i<list.size();i++)
  41. {
  42. %>
  43. <tr>
  44. <td><%=list.get(i).getId()%></td>
  45. <td><%=list.get(i).getUserName()%></td>
  46. <td><%=list.get(i).getMima()%></td>
  47. <td>
  48. <input type="checkbox" name="c" value="<%=list.get(i).getId()%>"/>
  49. <a href="../servlet?userI=<%=list.get(i).getId()%>">修改</a>
  50. <a href="../DeleteServlet?userI=<%=list.get(i).getId()%>">删除</a>
  51. </td>
  52. </tr>
  53. <%
  54. }
  55.  
  56. %>
  57. <tr>
  58. <td colspan="4"><a href="addData.jsp" style="text-decoration: none;">增加</a>
  59. <button type="submit">批量删除</button>
  60. </td>
  61. </tr>
  62. </table>
  63. </form>
  64. <form action="../DimServlet">
  65. <select name="se">
  66. <option value="id">序号</option>
  67. <option value="name">姓名</option>
  68. </select>
  69. <input type="text" name="in"/>
  70. <button type="submit">模糊查询</button>
  71. </form>
  72. </body>
  73.  
  74. </html>

2.增加数据的界面

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10. <form action="../AddServlet" method="post">
  11.  
  12. 用户名:<input type="text" name="userName" ><br/>
  13. 密码:<input type="password" name="mima" ><br/>
  14. ID:<input type="text" name="id" />
  15. <button type="submit">提交</button>
  16.  
  17. </form>
  18. </body>
  19. </html>

3.修改数据的界面

  1. <%@page import="com.zdsofe.work.Student"%>
  2. <%@ page language="java" contentType="text/html; charset=UTF-8"
  3. pageEncoding="UTF-8"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>Insert title here</title>
  9. </head>
  10.  
  11. <%
  12. //获取用户信息
  13. Student stu=(Student)session.getAttribute("user");
  14. %>
  15. <body>
  16.  
  17. <form action="../EditServlet" method="post">
  18.  
  19. 用户名:<input type="text" name="userName" value="<%=stu.getUserName()%>"><br/>
  20. 密码:<input type="password" name="mima" value="<%=stu.getMima()%>"><br/>
  21. ID:<input type="text" name="id" value="<%=stu.getId()%>"/>
  22. <button type="submit">提交</button>
  23.  
  24. </form>
  25.  
  26. </body>
  27. </html>

4.模糊查询后的界面

  1. <%@page import="com.zdsofe.work.Student"%>
  2. <%@page import="java.util.List"%>
  3. <%@page import="com.zdsofe.work.ReadData"%>
  4. <%@ page language="java" contentType="text/html; charset=UTF-8"
  5. pageEncoding="UTF-8"%>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Insert title here</title>
  11. </head>
  12. <% ReadData rd=new ReadData();
  13. String se=session.getAttribute("se").toString();
  14. String in=session.getAttribute("in").toString();
  15. List<Student> list= rd.findDim(se,in);
  16.  
  17. %>
  18. <body>
  19. <table border="1">
  20. <tr>
  21. <th>序号</th>
  22. <th>名字</th>
  23. <th>密码</th>
  24. <th>操作</th>
  25. </tr>
  26.  
  27. <%
  28. for(int i=0;i<list.size();i++)
  29. {
  30. %>
  31. <tr>
  32. <td><%=list.get(i).getId()%></td>
  33. <td><%=list.get(i).getUserName()%></td>
  34. <td><%=list.get(i).getMima()%></td>
  35.  
  36. <td>
  37. <a href="../servlet?userI=<%=list.get(i).getId()%>">修改</a>
  38. <a href="../DeleteServlet?userI=<%=list.get(i).getId()%>">删除</a>
  39. </td>
  40. </tr>
  41.  
  42. <%
  43. }
  44.  
  45. %>
  46. <tr>
  47. <td colspan="4"><a href="addData.jsp">增加</a>
  48.  
  49. </td>
  50. </tr>
  51. </table>
  52. </body>
  53. </html>

5.连接数据库的工具类

  1. package com.zdsofe.util;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class DBUtil {
  8. private static String DRIVER="com.mysql.jdbc.Driver";
  9. private static String URL="jdbc:mysql://localhost:3306/mysql";
  10. private static String user="root";
  11. private static String key="775297";
  12. public static Connection conn;
  13.  
  14. //加载驱动
  15. static{
  16. try {
  17. Class.forName(DRIVER);
  18. } catch (ClassNotFoundException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. //连接数据库
  23. public static Connection getConnection(){
  24. try {
  25. conn = DriverManager.getConnection(URL, user, key);
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. }
  29. return conn;
  30. }
  31. }

6.实体类

  1. package com.zdsofe.work;
  2.  
  3. public class Student {
  4. public String id;
  5. public String userName;
  6. public String mima;
  7.  
  8. public Student(String id, String userName, String mima) {
  9. super();
  10. this.id = id;
  11. this.userName = userName;
  12. this.mima = mima;
  13. }
  14.  
  15. public Student(String userName, String mima) {
  16.  
  17. this.userName = userName;
  18. this.mima = mima;
  19. }
  20.  
  21. public Student() {
  22. super();
  23. }
  24.  
  25. public String getId() {
  26. return id;
  27. }
  28. public void setId(String id) {
  29. this.id = id;
  30. }
  31. public String getUserName() {
  32. return userName;
  33. }
  34. public void setUserName(String userName) {
  35. this.userName = userName;
  36. }
  37. public String getMima() {
  38. return mima;
  39. }
  40. public void setMima(String mima) {
  41. this.mima = mima;
  42. }
  43.  
  44. }

7.一些实现功能的静态方法

  1. package com.zdsofe.work;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import com.zdsofe.util.DBUtil;
  10.  
  11. public class ReadData {
  12.  
  13. //查询信息
  14. public static List<Student> findInfo() {
  15. List <Student>list=new ArrayList<>();
  16. //调用连接并创建SQL语句
  17. try {
  18. Statement stam= DBUtil.getConnection().createStatement();
  19. String sql="SELECT id,userName,mima FROM denglu;";
  20. ResultSet rs=stam.executeQuery(sql);
  21.  
  22. while(rs.next())
  23. {
  24. String id=rs.getString("id");
  25. String userName=rs.getString("userName");
  26. String mima=rs.getString("mima");
  27. Student stu=new Student(id,userName,mima);
  28. list.add(stu);
  29. }
  30.  
  31. } catch (SQLException e) {
  32. e.printStackTrace();
  33. }
  34.  
  35. return list;
  36. }
  37.  
  38. //模糊查询
  39. public static List<Student> findDim(String se,String in ) {
  40. List <Student>list=new ArrayList<>();
  41.  
  42. if(se.equals("id"))
  43. { //调用连接并创建SQL语句
  44. try {
  45. Statement stam= DBUtil.getConnection().createStatement();
  46. String sql="select * from denglu where id like '%"+in+"%'";
  47. ResultSet rs=stam.executeQuery(sql);
  48. while(rs.next())
  49. {
  50. String id=rs.getString("id");
  51. String userName=rs.getString("userName");
  52. String mima=rs.getString("mima");
  53. Student stu=new Student(id,userName,mima);
  54. list.add(stu);
  55. }
  56.  
  57. } catch (SQLException e) {
  58. e.printStackTrace();
  59. }
  60. }
  61. if(se.equals("name"))
  62. {
  63. try {
  64. Statement stam= DBUtil.getConnection().createStatement();
  65. String sql="select * from denglu where userName like '%"+in+"%'";
  66.  
  67. ResultSet rs=stam.executeQuery(sql);
  68.  
  69. while(rs.next())
  70. {
  71. String id=rs.getString("id");
  72. String userName=rs.getString("userName");
  73. String mima=rs.getString("mima");
  74. Student stu=new Student(id,userName,mima);
  75. list.add(stu);
  76. }
  77.  
  78. } catch (SQLException e) {
  79. e.printStackTrace();
  80. }
  81. }
  82.  
  83. return list;
  84. }
  85. /* 根据用户名查询用户信息
  86. * @param userName
  87. * @return
  88. */
  89. public static Student findUserByName(String id)
  90. {
  91. Student stu=null;
  92. //输出查询sql
  93. String sql = "select * from denglu t where t.id='"+id+"'";
  94. try {
  95. //调用连接并创建SQL语句
  96. Statement stam= DBUtil.getConnection().createStatement();
  97. ResultSet rs=stam.executeQuery(sql);
  98. if(rs.next())
  99. {
  100. String i=rs.getString("id");
  101. String name=rs.getString("userName");
  102. String mima=rs.getString("mima");
  103. stu=new Student(i,name,mima);
  104. }
  105.  
  106. } catch (SQLException e) {
  107. e.printStackTrace();
  108.  
  109. }
  110. return stu;
  111. }
  112.  
  113. /**
  114. * 根据编码修改用户信息
  115. * @param user
  116. * @return
  117. */
  118. public static int update(Student stu)
  119. {
  120. //执行sql的结果
  121. int result = 0;
  122. //更新sql
  123.  
  124. String sql = "update denglu t set t.userName='"+stu.getUserName()+"',t.mima = '"+stu.getMima()+"' where t.id ='"+stu.getId()+"'";
  125. try {
  126. Statement stam= DBUtil.getConnection().createStatement();
  127. result=stam.executeUpdate(sql);
  128.  
  129. } catch (SQLException e) {
  130. e.printStackTrace();
  131. }
  132.  
  133. return result;
  134. }
  135. }

8.查询数据的servlet

  1. package com.zdsofe.work;
  2.  
  3. import java.io.IOException;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import javax.servlet.ServletException;
  9. import javax.servlet.annotation.WebServlet;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import javax.servlet.http.HttpSession;
  14.  
  15. import com.zdsofe.util.DBUtil;
  16.  
  17. /**
  18. * Servlet implementation class servlet
  19. */
  20. @WebServlet("/servlet")
  21. public class servlet extends HttpServlet {
  22. private static final long serialVersionUID = 1L;
  23.  
  24. /**
  25. * @see HttpServlet#HttpServlet()
  26. */
  27. public servlet() {
  28. super();
  29. // TODO Auto-generated constructor stub
  30. }
  31.  
  32. /**
  33. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  34. */
  35. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  36. //解决乱码问题
  37. request.setCharacterEncoding("utf-8");
  38. response.setCharacterEncoding("utf-8");
  39. response.setContentType("text/html charset=utf-8");
  40.  
  41. //获取用户id:
  42. String userI = request.getParameter("userI");
  43.  
  44. //根据用户id查询某一条用户信息
  45. Student stu=ReadData.findUserByName(userI);
  46. HttpSession session = request.getSession();
  47. session.setAttribute("user", stu);
  48. session.setAttribute("title", "修改用户");
  49. response.sendRedirect(request.getContextPath()+"/pages/edit.jsp");
  50. }
  51.  
  52. /**
  53. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  54. */
  55. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  56.  
  57. }
  58.  
  59. }

9..增加数据的servlet

  1. package com.zdsofe.work;
  2.  
  3. import java.io.IOException;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. import javax.servlet.ServletException;
  8. import javax.servlet.annotation.WebServlet;
  9. import javax.servlet.http.HttpServlet;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12.  
  13. import com.zdsofe.util.DBUtil;
  14.  
  15. /**
  16. * Servlet implementation class AddServlet
  17. */
  18. @WebServlet("/AddServlet")
  19. public class AddServlet extends HttpServlet {
  20. private static final long serialVersionUID = 1L;
  21.  
  22. /**
  23. * @see HttpServlet#HttpServlet()
  24. */
  25. public AddServlet() {
  26. super();
  27. // TODO Auto-generated constructor stub
  28. }
  29.  
  30. /**
  31. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  32. */
  33. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  34. // TODO Auto-generated method stub
  35. }
  36.  
  37. /**
  38. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  39. */
  40. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  41. int i=0;
  42.  
  43. //请求和响应页面的编码格式修改
  44. request.setCharacterEncoding("UTF-8");
  45. response.setCharacterEncoding("utf-8");
  46. response.setContentType("text/html charset=utf-8");
  47.  
  48. String sql="insert into denglu values('"+request.getParameter("id")+"','"+request.getParameter("userName")+"','"+request.getParameter("mima")+"')";
  49. try {
  50. Statement stam=DBUtil.getConnection().createStatement();
  51. i=stam.executeUpdate(sql);
  52. } catch (SQLException e) {
  53. e.printStackTrace();
  54. }
  55. if(i==1)
  56. {
  57. response.sendRedirect(request.getContextPath()+"/pages/student.jsp");
  58. }
  59. }
  60.  
  61. }

10.删除数据的servlet

  1. package com.zdsofe.work;
  2.  
  3. import java.io.IOException;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. import javax.servlet.ServletException;
  8. import javax.servlet.annotation.WebServlet;
  9. import javax.servlet.http.HttpServlet;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12.  
  13. import com.zdsofe.util.DBUtil;
  14.  
  15. /**
  16. * Servlet implementation class DeleteServlet
  17. */
  18. @WebServlet("/DeleteServlet")
  19. public class DeleteServlet extends HttpServlet {
  20. private static final long serialVersionUID = 1L;
  21.  
  22. /**
  23. * @see HttpServlet#HttpServlet()
  24. */
  25. public DeleteServlet() {
  26. super();
  27. // TODO Auto-generated constructor stub
  28. }
  29.  
  30. /**
  31. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  32. */
  33. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  34.  
  35. //获取要删除的用户ID
  36. String userId = request.getParameter("userI");
  37. //删除的sql语句
  38. String sql = "delete from denglu where id = "+userId+"";
  39.  
  40. try {
  41. Statement stam= DBUtil.getConnection().createStatement();
  42. stam.executeUpdate(sql);
  43. } catch (SQLException e) {
  44. // TODO Auto-generated catch block
  45. e.printStackTrace();
  46. }
  47. response.sendRedirect(request.getContextPath()+"/pages/student.jsp");
  48. }
  49.  
  50. /**
  51. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  52. */
  53. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  54. // TODO Auto-generated method stub
  55. }
  56.  
  57. }

11.模糊查询的servlet

  1. package com.zdsofe.work;
  2.  
  3. import java.io.IOException;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import javax.servlet.ServletException;
  9. import javax.servlet.annotation.WebServlet;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13.  
  14. import com.zdsofe.util.DBUtil;
  15.  
  16. /**
  17. * Servlet implementation class DimServlet
  18. */
  19. @WebServlet("/DimServlet")
  20. public class DimServlet extends HttpServlet {
  21. private static final long serialVersionUID = 1L;
  22.  
  23. /**
  24. * @see HttpServlet#HttpServlet()
  25. */
  26. public DimServlet() {
  27. super();
  28. // TODO Auto-generated constructor stub
  29. }
  30.  
  31. /**
  32. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  33. */
  34. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  35.  
  36. //请求和响应页面的编码格式修改
  37. request.setCharacterEncoding("UTF-8");
  38. response.setCharacterEncoding("utf-8");
  39. response.setContentType("text/html charset=utf-8");
  40.  
  41. //获取输入的模糊数据
  42. String se=request.getParameter("se");
  43. String in=request.getParameter("in");
  44.  
  45. ReadData.findDim(se,in);
  46. request.getSession().setAttribute("se", se);
  47. request.getSession().setAttribute("in", in);
  48.  
  49. /* request.getRequestDispatcher("/pages/newStudent.jsp").forward(request, response);*/
  50. response.sendRedirect(request.getContextPath()+"/pages/newStudent.jsp");
  51. }
  52.  
  53. /**
  54. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  55. */
  56. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  57.  
  58. }
  59.  
  60. }

12.修改数据的servlet

  1. package com.zdsofe.work;
  2.  
  3. import java.io.IOException;
  4. import java.lang.reflect.InvocationTargetException;
  5. import java.util.Enumeration;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. import javax.servlet.ServletException;
  10. import javax.servlet.annotation.WebServlet;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14.  
  15. import org.apache.commons.beanutils.BeanUtils;
  16.  
  17. /**
  18. * Servlet implementation class EditServlet
  19. */
  20. @WebServlet("/EditServlet")
  21. public class EditServlet extends HttpServlet {
  22. private static final long serialVersionUID = 1L;
  23.  
  24. /**
  25. * @see HttpServlet#HttpServlet()
  26. */
  27. public EditServlet() {
  28. super();
  29. // TODO Auto-generated constructor stub
  30. }
  31.  
  32. /**
  33. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  34. */
  35. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  36. //请求和响应页面的编码格式修改
  37.  
  38. request.setCharacterEncoding("UTF-8");
  39. response.setCharacterEncoding("utf-8");
  40. response.setContentType("text/html charset=utf-8");
  41. /*//获取表单中的所用控件name属性
  42. Enumeration<String> en = request.getParameterNames();
  43. Map<String, Object> mapObj = new HashMap<>();
  44. //实例化一个Student对象
  45. Student stu=new Student();
  46. while(en.hasMoreElements())
  47. {
  48. String rs = en.nextElement();
  49. mapObj.put(rs, request.getParameter("rs"));
  50. }
  51. try {
  52. BeanUtils.populate(stu, mapObj);
  53.  
  54. } catch (IllegalAccessException | InvocationTargetException e) {
  55. e.printStackTrace();
  56. }*/
  57. String name=request.getParameter("userName");
  58. String mima=request.getParameter("mima");
  59. String id=request.getParameter("id");
  60.  
  61. Student stu=new Student(id,name,mima);
  62. //根据条件修改用户信息,调用执行sql方法
  63.  
  64. int upResult = ReadData.update(stu);
  65.  
  66. if(upResult==1)
  67. {
  68. response.sendRedirect(request.getContextPath()+"/pages/student.jsp");
  69. }
  70.  
  71. }
  72.  
  73. /**
  74. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  75. */
  76. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  77. doGet(request, response);
  78. }
  79.  
  80. }

13.删除多个的servlet

  1. package com.zdsofe.work;
  2.  
  3. import java.io.IOException;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. import javax.servlet.ServletException;
  8. import javax.servlet.annotation.WebServlet;
  9. import javax.servlet.http.HttpServlet;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12.  
  13. import com.zdsofe.util.DBUtil;
  14.  
  15. /**
  16. * Servlet implementation class MoreDeleteServlet
  17. */
  18. @WebServlet("/MoreDeleteServlet")
  19. public class MoreDeleteServlet extends HttpServlet {
  20. private static final long serialVersionUID = 1L;
  21.  
  22. /**
  23. * @see HttpServlet#HttpServlet()
  24. */
  25. public MoreDeleteServlet() {
  26. super();
  27. // TODO Auto-generated constructor stub
  28. }
  29.  
  30. /**
  31. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  32. */
  33. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  34.  
  35. String[] id=request.getParameterValues("c");
  36.  
  37. if(id.length>0)
  38. {
  39. for(int i=0;i<id.length;i++)
  40. {
  41. //删除的sql语句
  42. String sql = "delete from denglu where id = "+id[i]+"";
  43. try {
  44. Statement stam= DBUtil.getConnection().createStatement();
  45. stam.executeUpdate(sql);
  46. } catch (SQLException e) {
  47. e.printStackTrace();
  48. }
  49.  
  50. }
  51. }
  52. response.sendRedirect(request.getContextPath()+"/pages/student.jsp");
  53. }
  54.  
  55. /**
  56. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  57. */
  58. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  59. // TODO Auto-generated method stub
  60. }
  61.  
  62. }

(MVC)javaBaen+jsp+servlet对数据的操作的更多相关文章

  1. (jsp+servlet+javabean )MVC架构

    MVC是三个单词的缩写,这三个单词分别为:模型.视图和控制. 使用的MVC的目的:在于将M和V的实现代码分离,从而使同一个程序可以使用不同的表现形式.比如Windows系统资源管理器文件夹内容的显示方 ...

  2. 深入浅出Java MVC(Model View Controller) ---- (JSP + servlet + javabean实例)

    在DRP中终于接触到了MVC,感触是确实这样的架构系统灵活性不少,现在感触最深的就是使用tomcat作为服务器发布比IIS好多了,起码发布很简单,使用起来方便. 首先来简单的学习一下MVC的基础知识, ...

  3. JSP Servlet SQL 三者之间数据传递

    前言: 最近一直在做WEB开发,现总结一下这一段时间的体会和感触. 切记,web开发重点在于前台数据交互,页面美化而不要太沉溺于底层数据. 浏览器时代来到,向我们召唤出更炫.更简洁.更方便.更大气的网 ...

  4. 软件架构设计学习总结(18):MVC三层架构在各框架(jsp+servlet + Struts1+ Struts2+ springMVC)中的特征

    1.基于web开发中最原始的jsp+Servlet   图形化理解jsp+servlet结构: 1.从结构上分析jsp+servlet图解原理: 在基于mvc设计模式下的最原始的jsp+Servlet ...

  5. Jsp+Servlet+JavaBean经典MVC模式理解

    MVC模式目的(实现Web系统的职能分工). 在Java EE中,Jsp+Servlet+JavaBean算是里面经典的模式,是初学者必备的知识技能.M, Model(模型)实现系统的业务逻辑 1.通 ...

  6. 基于jsp+servlet图书管理系统之后台用户信息查询操作

    上一篇的博客写的是插入操作,且附有源码和数据库,这篇博客写的是查询操作,附有从头至尾写的代码(详细的注释)和数据库! 此次查询操作的源码和数据库:http://download.csdn.net/de ...

  7. MVC jsp+servlet+javabean 连接Mysql数据库測试demo

    本文介绍的是怎样使用MVC架构去实现jsp+servlet+javabean连接数据库 首先我们应该了解什么是MVC: MVC包含三个部分 : ①View:由各种JSP页面组成. ②Controlle ...

  8. 基于jsp+servlet图书管理系统之后台用户信息删除操作

    上一篇的博客写的是修改操作,且附有源码和数据库,这篇博客写的是删除操作,附有从头至尾写的代码(详细的注释)和数据库! 此次删除操作的源码和数据库:http://download.csdn.net/de ...

  9. Servlet程序开发--实例操作:MVC设计模式应用

    以前做过一个登录程序,是用JSP+JavaBean完成的,最大的问题,JSP文件内容太多了. 1. VO 2. DBC 3. DAO 3.1 impl 3.2 proxy 4. Factory 5. ...

随机推荐

  1. ZooKeeper数据模型

    ZooKeeper有一个分层的命名空间,类似分布式文件系统.它们唯一的区别就在于在命名空间中每个节点可以有数据关联作为它们的子节点.这就像有一个文件系统允许文件也作为文件目录.节点路径通常表示为规范的 ...

  2. 计时器60s

    计时器是经常用到的功能,下面以react nativ的例子简介来写一个倒计时60s的小demo. 代码如下: import React, { Component } from 'react'; imp ...

  3. asp.net web api实现图片点击式图片验证码

    现在验证码的形式越来越丰富,今天要实现的是在点击图片中的文字来进行校验的验证码,如图 这种验证码验证是验证鼠标是否选中了图片中文字的位置,以及选择的顺序,产生验证码的时候可以提供一组底图,然后随机获取 ...

  4. Objective-C 编码风格指南

    本文转自:[Objective-C 编码风格指南 | www.samirchen.com][2] ## 背景 保证自己的代码遵循团队统一的编码规范是一个码农的基本节操,能够进入一个有统一编码规范的团队 ...

  5. 让gdb能打印C++中的容器类型

    由于原生的gdb对vector,map等容器的支持不太好,所以找到了一个工具,将这个工具集成到gdb中,就可以实现map,vector等容器的内容的打印操作. 1.用vim将下方的代码拷贝到一个新的文 ...

  6. Array和ArrayList的区别与联系

    博主今天去了一个java的实习面试,发现有好多java最基础的数据结构对于博主来说反而感到陌生,在面试官问一些常见的例如HashMap这样的数据结构,博主能回答的头头是道,但是在问到Array和Arr ...

  7. 【LeetCode】138. Copy List with Random Pointer

    题目: A linked list is given such that each node contains an additional random pointer which could poi ...

  8. 3.MQTT paho

    一.概述 遥测传输 (MQTT) 是轻量级基于代理的发布/订阅的消息传输协议,设计思想是开放.简单.轻量.易于实现.这些特点使它适用于受限环境.例如,但不仅限于此: 网络代价昂贵,带宽低.不可靠. 在 ...

  9. iOS- 解决iOS10 App启动时放大铺满App Icon的问题

    0.前言 iOS10 App启动时放大铺满App图标 iPad Application shows app icon as launch screen in iOS 10 如图,点击APP后APP图标 ...

  10. Pycharm直接连接Github

    Pycharm可以说是使用Python语言开发者的必备利器.高校学生有学生邮箱就可以免费使用,着实省了我不少银两.附个license图: Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很 ...