forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReaderType.java
More file actions
152 lines (141 loc) · 5.17 KB
/
ReaderType.java
File metadata and controls
152 lines (141 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.action;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.actionForm.ReaderTypeForm;
import com.dao.ReaderTypeDAO;
public class ReaderType extends HttpServlet {
private ReaderTypeDAO readerTypeDAO = null;
public ReaderType() {
this.readerTypeDAO = new ReaderTypeDAO();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
System.out.println("\nreaderType*********************action=" + action);
if (action == null || "".equals(action)) {
request.setAttribute("error", "您的操作有误!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if ("readerTypeAdd".equals(action)) {
readerTypeAdd(request, response);
} else if ("readerTypeQuery".equals(action)) {
readerTypeQuery(request, response);
} else if ("readerTypeModifyQuery".equals(action)) {
readerTypeModifyQuery(request, response);
} else if ("readerTypeModify".equals(action)) {
readerTypeModify(request, response);
} else if ("readerTypeDel".equals(action)) {
readerTypeDel(request, response);
}
}
/***********************
* 添加读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReaderTypeForm readerTypeForm = new ReaderTypeForm();
System.out.println("servlet:" + request.getParameter("name"));
readerTypeForm.setName(request.getParameter("name"));
readerTypeForm.setNumber(Integer.parseInt(request
.getParameter("number")));
int a = readerTypeDAO.insert(readerTypeForm);
if (a == 0) {
request.setAttribute("error", "读者类型信息添加失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else if (a == 2) {
request.setAttribute("error", "该读者类型信息已经添加!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("readerType_ok.jsp?para=1").forward(
request, response);
}
}
/***********************
* 查询全部读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String str = null;
request.setAttribute("readerType", readerTypeDAO.query(str));
request.getRequestDispatcher("readerType.jsp").forward(request,
response);
}
/***********************
* 查询修改读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeModifyQuery(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReaderTypeForm readerTypeForm = new ReaderTypeForm();
readerTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
request.setAttribute("readerTypeQueryif", readerTypeDAO
.queryM(readerTypeForm));
request.getRequestDispatcher("readerType_Modify.jsp").forward(request,
response);
}
/***********************
* 修改读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeModify(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReaderTypeForm readerTypeForm = new ReaderTypeForm();
readerTypeForm.setId(Integer.parseInt(request.getParameter("id")));
readerTypeForm.setName(request.getParameter("name"));
readerTypeForm.setNumber(Integer.parseInt(request
.getParameter("number")));
int ret = readerTypeDAO.update(readerTypeForm);
if (ret == 0) {
request.setAttribute("error", "修改读者类型信息失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("readerType_ok.jsp?para=2").forward(
request, response);
}
}
/***********************
* 删除读者类型信息
*
* @throws IOException
* @throws ServletException
* *
*************************/
private void readerTypeDel(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReaderTypeForm readerTypeForm = new ReaderTypeForm();
readerTypeForm.setId(Integer.valueOf(request.getParameter("ID")));
int ret = readerTypeDAO.delete(readerTypeForm);
if (ret == 0) {
request.setAttribute("error", "删除读者类型信息失败!");
request.getRequestDispatcher("error.jsp")
.forward(request, response);
} else {
request.getRequestDispatcher("readerType_ok.jsp?para=3").forward(
request, response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}