jsp 实现修改和删除功能
1 package servlet;
2
3 import ;
4 import ;
5
6 import ;
7 import ;
8 import ;
9 import ;
10
11 import ;
12 import ;
13
14 public class EditServlet extends HttpServlet {
15
16 /**
17 * Constructor of the object.
18 */
19 public EditServlet() {
20 super();
21 }
22
23 /**
24 * Destruction of the servlet. <br>
25 */
26 public void destroy() {
27 super.destroy(); // Just puts "destroy" string in log
28 // Put your code here
29 }
30
31 /**
32 * The doGet method of the servlet. <br>
33 *
34 * This method is called when a form has its tag value method equals to get.
35 *
36 * @param request the request send by the client to the server
37 * @param response the response send by the server to the client
38 * @throws ServletException if an error occurred
39 * @throws IOException if an error occurred
40 */
41 public void doGet(HttpServletRequest request, HttpServletResponse response)
42 throws ServletException, IOException {
43
44 doPost(request,response);
45 }
46
47 /**
48 * The doPost method of the servlet. <br>
49 *
50 * This method is called when a form has its tag value method equals to post.
51 *
52 * @param request the request send by the client to the server
53 * @param response the response send by the server to the client
54 * @throws ServletException if an error occurred
55 * @throws IOException if an error occurred
56 */
57 public void doPost(HttpServletRequest request, HttpServletResponse response)
58 throws ServletException, IOException {
59
60 ("text/html");
61 PrintWriter out = ();
62 out
63 .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
64 ("<HTML>");
65 (" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
66 (" <BODY>");
67 //获取edit 传递的字段
68
69 String userid=("userid");
70 String username=("username");
71 String userpwd=("userpwd");
72 String sex=("sex");
73 String age=("age");
74 String address=("address");
75
76 User u=new User();
77 ((userid));
78 (username);
79 (userpwd);
80 (sex);
81 ((age));
82 (address);
83
84 //调用方法
85 UserDAO udao=new UserDAO();
86
87 int n=(u);
88 if(n>0) {
89 //成功就调用查询方法 看修改完后的
90 ("../servlet/GetUsersServlet");
91 }
92 else
93 {
94 ("修改失败");
95 }
96
97
98
99 (" </BODY>");
100 ("</HTML>");
101 ();
102 ();
103 }
104
105 /**
106 * Initialization of the servlet. <br>
107 *
108 * @throws ServletException if an error occurs
109 */
110 public void init() throws ServletException {
111 // Put your code here
112 }
113
114 }