java web简单的增删改查
1、主要的文件,运行结果,运行界面,数据库创建的表等图片。
所要创建的文件和要导入的包:
主页面:
显示界面:
数据库的信息:
删除、查找、修改就不一 一列出来,自己可以运行看看。哈哈
2、接下来我将给你分享一下我的代码:
//User类
1 package com.newjavaweb;
2 public class User implements Comparable{
3 private String id;
4 private String name;
5 private String clas;
6 private String ke;
7 private String score;
8
9 public String getId() {
10 return id;
11 }
12
13 public void setId(String id) {
14 this.id = id;
15 }
16
17 public String getName() {
18 return name;
19 }
20
21 public void setName(String name) {
22 this.name = name;
23 }
24
25 public String getClas() {
26 return clas;
27 }
28
29 public void setClas(String clas) {
30 this.clas = clas;
31 }
32
33 public String getKe() {
34 return ke;
35 }
36
37 public void setKe(String ke) {
38 this.ke = ke;
39 }
40
41 public String getScore() {
42 return score;
43 }
44
45 public void setScore(String score) {
46 this.score = score;
47 }
48
49 public User(String id, String name, String clas, String ke, String score) {
50 super();
51 this.id = id;
52 this.name = name;
53 this.clas = clas;
54 this.ke = ke;
55 this.score = score;
56 }
57 public int compareTo(Object o)
58 {
59 User s=(User)o;
60 int result = 0;
61 if(score.length()==s.score.length()) {
62 if(score.compareTo(s.score)>0)
63 result=1;
64 else if(score.compareTo(s.score)<0)
65 result=-1;
66 }
67 if(score.length()>s.score.length())
68 result=1;
69 if(score.length()<s.score.length())
70 result=-1;
71 return result;
72 }
73 }
//userdao类
1 package Dao;
2
3 import java.io.IOException;
4 import java.sql.Connection;
5 import java.sql.PreparedStatement;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8 import java.sql.Statement;
9 import java.util.ArrayList;
10 import java.util.Arrays;
11 import java.util.Collections;
12 import java.util.Comparator;
13 import java.util.List;
14 import javax.servlet.ServletException;
15 import javax.servlet.ServletResponse;
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18 import util.DBUtil;
19 import com.newjavaweb.User;
20
21 public class userdao {
22 public boolean add(User user) {
23 String sql = "insert into text(id,name,clas,ke,score)" + "values('" + user.getId() + "','" + user.getName()+ "','" + user.getClas() + "','" + user.getKe()+ "','" + user.getScore()+ "')";
24 Connection conn = DBUtil.getConn();//调用方法连接数据库
25 Statement state = null;//创建一个Statement对象来执行静态的SQL语句
26 //Statement用于在已经建立数据库连接上发送静态的SQL语句
27 boolean f = false;
28 int a = 0 ;
29
30 try { //监视大括号内的代码
31 state = conn.createStatement();//上面的是详解
32 a = state.executeUpdate(sql);
33 //执行指定的更新类的SQl语句,并返回操作结果的整型值
34 } catch (Exception e) { //捕获错误
35 e.printStackTrace();
36 } finally {
37 //关闭z 连接
38 DBUtil.close(state, conn);
39 }
40
41 if (a > 0) {
42 f = true;
43 }
44 return f;
45 }
46
47
48 public static List<User> loadview(String sql) {
49 // TODO Auto-generated method stub
50 String sql1="select * from text "+ sql;
51 List<User> list =new ArrayList<User>();
52 Connection con=null;
53 PreparedStatement psts=null;
54 ResultSet rs=null;
55 try
56 {
57 con=DBUtil.getConn();
58 //String sql="select * from course";
59 psts=con.prepareStatement(sql1);
60 rs=psts.executeQuery();//记录返回的结果
61 while(rs.next())
62 {
63 String id=rs.getString("id");
64 String name=rs.getString("name");
65 String clas=rs.getString("clas");
66 String ke=rs.getString("ke");
67 String score=rs.getString("score");
68
69 User yi=new User(id,name,clas,ke,score);
70 list.add(yi);
71 }
72
73 DBUtil.close(rs, psts, con);
74 } catch (SQLException e) {
75 // TODO 自动生成的 catch 块
76 e.printStackTrace();
77 }
78
79 return list;
80 }
81 //return null;
82
83
84
85
86 public String find(String name)
87 {
88 String sql = "select * from text where ";
89 if (name!= "") {
90 sql += "name like '" + name +"'";
91 }
92 Connection conn = DBUtil.getConn();
93 Statement state = null;
94 ResultSet rs = null;
95 String username2="@";
96 try {
97 state = conn.createStatement();
98 rs = state.executeQuery(sql);
99 while (rs.next()) {
100
101 username2 = rs.getString("name");
102
103 }
104 } catch (SQLException e) {
105 e.printStackTrace();
106 } finally {
107 DBUtil.close(rs, state, conn);
108 }
109 return username2;
110 }
111
112 public String search(String name) {
113 String sql = "select * from text where ";
114 if (name!= "") {
115 sql += "name like '%" + name + "%'";
116 }
117
118 Connection conn = DBUtil.getConn();
119 Statement state = null;
120 ResultSet rs = null;
121 String name2 = "@";
122 try {
123 state = conn.createStatement();
124 rs = state.executeQuery(sql);
125 while (rs.next()) {
126
127 name2 = rs.getString("name");
128
129 }
130 } catch (SQLException e) {
131 e.printStackTrace();
132 } finally {
133 DBUtil.close(rs, state, conn);
134 }
135
136 return name2;
137 }
138
139
140 public String search1(String id, String name, String clas, String ke, String score) {
141 String sql = "select * from text where ";
142 if (id!= "") {
143 sql += "id like '%" + id + "%'";
144 }
145 else if(name!="")
146 {
147 sql += "name like '%" + name + "%'";
148 }
149 else if(clas!="")
150 {
151 sql += "clas like '%" + clas + "%'";
152 }
153 else if(ke!="")
154 {
155 sql += "ke like '%" + ke + "%'";
156 }
157 else if(score!="")
158 {
159 sql += "score like '%" + score + "%'";
160 }
161 Connection conn = DBUtil.getConn();
162 Statement state = null;
163 ResultSet rs = null;
164 String name2 = "@";
165 try {
166 state = conn.createStatement();
167 rs = state.executeQuery(sql);
168 while (rs.next()) {
169
170 name2 = rs.getString("name");
171
172 }
173 } catch (SQLException e) {
174 e.printStackTrace();
175 } finally {
176 DBUtil.close(rs, state, conn);
177 }
178
179 return name2;
180 }
181
182 public List<User> examine(String name1) throws ServletException, IOException {
183 String sql = "select * from text where ";
184 if (name1!= "") {
185 sql += "name like '%" + name1 + "%'";
186 }
187 List<User> list1 = new ArrayList<>();
188 Connection conn = DBUtil.getConn();
189 Statement state = null;
190 ResultSet rs = null;
191 try {
192 state = conn.createStatement();
193 rs = state.executeQuery(sql);
194 while (rs.next()) {
195 String id=rs.getString("id");
196 String name=rs.getString("name");
197 String clas=rs.getString("clas");
198 String ke=rs.getString("ke");
199 String score=rs.getString("score");
200 User bean2 = new User(id,name,clas,ke,score);
201 list1.add(bean2);
202 }
203 } catch (SQLException e) {
204 e.printStackTrace();
205 } finally {
206 DBUtil.close(rs, state, conn);
207 }
208 return list1;
209 }
210
211 public List<User> theall() {
212 String sql = "select * from text";//全部
213 List<User> list = new ArrayList<>();
214 Connection conn = DBUtil.getConn();
215 Statement state = null;
216 ResultSet rs = null;
217 try {
218 state = conn.createStatement();
219 rs = state.executeQuery(sql);
220 User bean = null;
221 if(rs!=null) {
222 while (rs.next()) {
223 String id=rs.getString("id");
224 String name=rs.getString("name");
225 String clas=rs.getString("clas");
226 String ke=rs.getString("ke");
227 String score=rs.getString("score");
228 bean = new User(id,name,clas,ke,score);
229 list.add(bean);
230 }
231 }
232 } catch (SQLException e) {
233 e.printStackTrace();
234 } finally {
235 DBUtil.close(rs, state, conn);
236 }
237 return list;
238 }
239
240
241
242
243 public boolean delete (String name) {
244 boolean f = false;
245 String sql = "delete from text where name='" + name + "'";
246 Connection conn = DBUtil.getConn();
247 Statement state = null;
248 int a = 0;
249 try {
250 state = conn.createStatement();
251 a = state.executeUpdate(sql);
252 } catch (SQLException e) {
253 e.printStackTrace();
254 }
255 finally {
256 DBUtil.close(state, conn);
257 }
258
259 if (a > 0) {
260 f = true;
261 }
262 return f;
263 }
264
265
266
267 public User getUserbyzhanghu(String name5) {
268 String sql = "select * from text where name ='" + name5 + "'";
269 Connection conn = DBUtil.getConn();
270 Statement state = null;
271 ResultSet rs = null;
272 User user3 = null;
273 try {
274 state = conn.createStatement();
275 rs = state.executeQuery(sql);
276 while (rs.next()) {
277 String id=rs.getString("id");
278 String name=rs.getString("name");
279 String clas=rs.getString("clas");
280 String ke=rs.getString("ke");
281 String score=rs.getString("score");
282 user3= new User(id,name,clas,ke,score);
283 }
284 } catch (Exception e) {
285 e.printStackTrace();
286 } finally {
287 DBUtil.close(rs, state, conn);
288 }
289 return user3;
290 }
291
292 public boolean update(User user,String zh)
293 {
294 String sql="update text set id='" + user.getId() + "',name='" + user.getName() + "',clas='" + user.getClas() + "',ke='" + user.getKe() + "',score='" + user.getScore() + "' where name='" + zh + "'";
295 Connection conn = DBUtil.getConn();
296 Statement state = null;
297 boolean f = false;
298 int a = 0;
299
300 try {
301 state = conn.createStatement();
302 a = state.executeUpdate(sql);
303 } catch (SQLException e) {
304 e.printStackTrace();
305 } finally {
306 DBUtil.close(state, conn);
307 }
308
309 if (a > 0) {
310 f = true;
311 }
312 return f;
313 }
314 public List<User> paixu(){
315 String sql = "select * from text";//全部
316 List<User> list = new ArrayList<>();
317 Connection conn = DBUtil.getConn();
318 Statement state = null;
319 ResultSet rs = null;
320 try {
321 state = conn.createStatement();
322 rs = state.executeQuery(sql);
323 User bean = null;
324 if(rs!=null) {
325 while (rs.next()) {
326 String id=rs.getString("id");
327 String name=rs.getString("name");
328 String clas=rs.getString("clas");
329 String ke=rs.getString("ke");
330 String score=rs.getString("score");
331 bean = new User(id,name,clas,ke,score);
332 list.add(bean);
333 }
334 }
335 } catch (SQLException e) {
336 e.printStackTrace();
337 } finally {
338 DBUtil.close(rs, state, conn);
339 }
340 list.sort(null);
341 return list;
342 }
343 }
//Servlet类
1 package servlet;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.annotation.WebServlet;
8 import javax.servlet.http.HttpServlet;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 import com.newjavaweb.User;
13
14 import Dao.userdao;
15
16 /**
17 * Servlet implementation class Servlet
18 */
19 @WebServlet("/Servlet")
20 public class Servlet extends HttpServlet {
21 private static final long serialVersionUID = 1L;
22
23 /**
24 * @see HttpServlet#HttpServlet()
25 */
26 public Servlet() {
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 // TODO Auto-generated method stub
36 request.setCharacterEncoding("utf-8");
37 response.setContentType("textml;charset=utf-8");
38
39
40
41
42 userdao dao=new userdao();
43 java.util.List<User> list= new ArrayList<User>();
44 String p[] = new String[5];//获得条件
45 String s[] = new String[5];//获得内容
46 String g[] = new String[5];//获得关系
47 String f[] = new String[5];//获得精确或者模糊
48 String number = null;
49
50 //String number1 = null;
51 number=request.getParameter("number1");
52 //number1=request.getParameter("number2");
53 int n = Integer.parseInt(number);//接收条件的个数
54 //int n1 = Integer.parseInt(number1);// յĹ ϵ ĸ
55 for(int i=1;i<=n;i++){
56 p[i]= (String) request.getParameter("s"+i);
57 s[i]=(String)request.getParameter("shuru"+i);
58 f[i]=(String)request.getParameter("c"+i);
59
60 System.out.println("精确还是模糊 "+f[i]);
61 System.out.println("条件 "+p[i]);
62 System.out.println("输入 "+s[i]);
63
64 if(p[i].equals("学号")){
65 p[i] = "id";
66 }
67 else if(p[i].equals("姓名")){
68 p[i] = "name";
69 }else if(p[i].equals("班级"))
70 {
71 p[i] = "clas";
72 }else if(p[i].equals("课程")){
73 p[i] = "ke";
74 }else if(p[i].equals("分数")){
75 p[i] = "score";
76 }
77
78
79
80 }
81
82 for(int i=1;i<n;i++){
83 g[i]=(String) request.getParameter("g"+i);
84 if(g[i].equals("且")) {
85 g[i]="and";
86 }else if(g[i].equals("或")) {
87 g[i]="or";
88 }
89
90 System.out.println("且或"+g[i]);
91 }
92
93 String sql="where ";
94 for(int i=1;i<n;i++){
95 if(s[i].equals("")){
96 continue;
97 }
98 if(f[i].equals("精确")){
99 sql=sql+p[i]+"='"+s[i]+"'"+" "+g[i]+" ";
100 }else if(f[i].equals("模糊")){
101 sql=sql+p[i]+" "+"LIKE"+" "+"'%"+s[i]+"%'"+" "+g[i]+" ";
102 }
103
104 }
105
106 if(f[n].equals("精确")) {
107 sql = sql + p[n]+"="+"'"+s[n]+"'";
108 }
109
110 else {
111 sql = sql + p[n]+" "+"LIKE"+" "+"'%"+s[n]+"%'";
112 }
113 if(n==1&&s[1].equals("")){
114 System.out.println("什么也没传!");
115 sql="";
116 }
117 list = dao.loadview(sql);
118
119 if(list.size()!=0) {
120 request.setAttribute("allthing",list);
121 request.setAttribute("message", "查询成功");
122 request.getRequestDispatcher("checkall.jsp").forward(request,response);
123 }
124 else {
125 request.setAttribute("message", "查询失败");
126 request.getRequestDispatcher("selectmore.jsp").forward(request,response);
127 }
128 // HttpSession session = request.getSession();
129 // session.setAttribute("tiaojian", list);
130 //// int servletid=1;
131 //// request.setAttribute("list", list);
132 //// request.setAttribute("servletid", servletid);
133 // try {
134 //// request.getRequestDispatcher("/admin/123.jsp").forward(request, response);
135 // response.sendRedirect(request.getContextPath()+"ow.jsp");
136 // } catch (IOException e) {
137 // // TODO Զ ɵ catch
138 // e.printStackTrace();
139 // }
140
141
142 }
143
144 /**
145 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
146 */
147 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
148 // TODO Auto-generated method stub
149 doGet(request, response);
150 }
151
152 }
//UserServlet类
1 package servlet;
2
3 import java.io.IOException;
4 import java.sql.ResultSet;
5
6 import javax.servlet.ServletException;
7 import javax.servlet.annotation.WebServlet;
8 import javax.servlet.http.HttpServlet;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 import javax.swing.JOptionPane;
12
13 import com.mysql.jdbc.Connection;
14 import com.mysql.jdbc.Statement;
15 import com.newjavaweb.User;
16 import Dao.userdao;
17 import util.DBUtil;
18
19 import java.util.List;
20 /**
21 * Servlet implementation class UserServlet
22 */
23 @WebServlet("/UserServlet")
24 public class UserServlet extends HttpServlet {
25 static String wen;
26 private static final long serialVersionUID = 1L;
27
28 /**
29 * @see HttpServlet#HttpServlet()
30 */
31 public UserServlet() {
32 super();
33 // TODO Auto-generated constructor stub
34 }
35 userdao dao = new userdao();
36
37 protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
38 req.setCharacterEncoding("utf-8");
39 String method = req.getParameter("method");
40 if ("add".equals(method))
41 {
42 add(req, resp);
43 }
44 else if("search".equals(method))
45 {
46 search(req, resp);
47 }
48 else if("delete".equals(method))
49 {
50 delete(req,resp);
51 }
52 else if("allall".equals(method))
53 {
54 allall(req,resp);
55 }
56 else if("look".equals(method))
57 {
58 look(req,resp);
59 }
60 else if("update".equals(method))
61 {
62 update(req,resp);
63 }
64 else if("deletecheck".equals(method))
65 {
66 deletecheck(req,resp);
67 }
68 else if("paixu".equals(method))
69 {
70 paixu(req,resp);
71 }
72 }
73
74
75 private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
76 // TODO Auto-generated method stub
77 req.setCharacterEncoding("utf-8");
78
79 String zhanghu = req.getParameter("zhanghu");
80 String psw = req.getParameter("psw");
81 String rpassword = dao.search(zhanghu);
82 String yanzheng1=req.getParameter("code");
83 String yanzheng=(String)req.getSession().getAttribute("code");
84
85 if(!yanzheng1.equals(yanzheng))
86 {
87 req.setAttribute("message", "验证码错误");
88 req.getRequestDispatcher("login.jsp").forward(req,resp);
89 }
90
91 if(psw.equals(rpassword)) {
92 //JOptionPane.showMessageDialog(null,"登陆成功!");
93 req.setAttribute("message", "登陆成功!");
94 req.getRequestDispatcher("NewFile.jsp").forward(req,resp);
95 }
96 else {
97 //JOptionPane.showMessageDialog(null,"账号不存在或密码错误!");
98 req.setAttribute("message", "账号不存在或密码错误!");
99 req.getRequestDispatcher("login.jsp").forward(req,resp);
100 }
101 }
102 private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
103 // TODO Auto-generated method stub
104 String id=req.getParameter("id");
105 String name=req.getParameter("name");
106 String clas=req.getParameter("clas");
107 String ke=req.getParameter("ke");
108 String score=req.getParameter("score");
109
110 User user= new User(id,name,clas,ke,score);
111
112 String rusername = dao.find(name);
113
114 if(!name.equals(rusername)) {
115 dao.add(user);
116
117 req.setAttribute("message", "添加成功!");
118 req.getRequestDispatcher("UserServlet?method=allall").forward(req, resp);
119 }else {
120
121 req.setAttribute("message", "账户重复,请重新输入!");
122 req.getRequestDispatcher("zc.jsp").forward(req, resp);
123 }
124 }
125
126 private void deletecheck(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
127 {
128 req.setCharacterEncoding("utf-8");
129 String name =req.getParameter("name4");
130 String rusername = dao.find(name);
131 if(!name.equals(rusername))
132 {
133 req.setAttribute("message", "用户不存在请重新输入");
134 req.getRequestDispatcher("delete.jsp").forward(req, resp);
135 return;
136 }
137 List<User> Thething1 =dao.examine(name);
138 req.setAttribute("Thething1", Thething1);
139 req.getRequestDispatcher("deletecheck2.jsp").forward(req, resp);
140 }
141
142 private void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
143 req.setCharacterEncoding("utf-8");
144 String name=req.getParameter("name");
145 boolean wen=dao.delete(name);
146 if(wen)
147 {
148 req.setAttribute("message", "删除成功!");
149 req.getRequestDispatcher("delete1.jsp").forward(req,resp);
150 }
151 else
152 {
153 req.setAttribute("message", "此用户不存在,删除失败");
154 req.getRequestDispatcher("delete.jsp").forward(req,resp);
155 }
156
157 }
158
159
160 private void paixu(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
161 {
162 req.setCharacterEncoding("utf-8");
163 List<User> allthing =dao.paixu();
164 req.setAttribute("allthing", allthing);
165 req.getRequestDispatcher("checkall.jsp").forward(req, resp);
166 }
167 private void allall(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
168 {
169 req.setCharacterEncoding("utf-8");
170 List<User> allthing = dao.theall();
171 req.setAttribute("allthing", allthing);
172 req.getRequestDispatcher("checkall.jsp").forward(req,resp);
173 }
174 private void look(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
175 {
176 req.setCharacterEncoding("utf-8");
177 String name5 = req.getParameter("name5");
178 wen=name5;
179 String q1=dao.find(name5);
180 if(q1.equals("@"))
181 {
182 req.setAttribute("message", "此用户不存在,不能进行修改");
183 req.getRequestDispatcher("updatesome.jsp").forward(req,resp);
184 return;
185 }
186 User user3 = dao.getUserbyzhanghu(name5);
187 req.setAttribute("user3", user3);
188 req.getRequestDispatcher("updatesome1.jsp").forward(req,resp);
189 }
190
191 private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
192 {
193 req.setCharacterEncoding("utf-8");
194 String id=req.getParameter("id6");
195 String name = req.getParameter("name6");
196 String clas=req.getParameter("clas6");
197 String ke=req.getParameter("ke6");
198 String score=req.getParameter("score6");
199
200 User user= new User(id,name,clas,ke,score);
201 dao.update(user,name);
202 req.setAttribute("message", "修改成功");
203 req.getRequestDispatcher("updatesome2.jsp").forward(req,resp);
204 }
205 }
//DBUtil类
1 package util;
2
3 //数据库连接
4 import java.sql.Connection;
5 import java.sql.DriverManager;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8 import java.sql.Statement;
9
10 /**
11 * 数据库连接工具
12 * @author Zheng
13 *
14 */
15 public class DBUtil {
16
17 public static String db_url = "jdbc:mysql://localhost:3306/student?useSSL=false";
18 public static String db_user = "root";
19 public static String db_pass = "001206";
20
21 public static Connection getConn () {
22 Connection conn = null;
23
24 try {
25 Class.forName("com.mysql.jdbc.Driver");//加载驱动
26 conn = DriverManager.getConnection(db_url, db_user, db_pass);//通过输入的用户名还有密码来建立一个到数据库的连接主要是调用connect()方法
27 } catch (Exception e) {
28 e.printStackTrace();
29 }
30
31 return conn;
32 }
33
34 /**
35 * 关闭连接
36 * @param state
37 * @param conn
38 */
39 public static void close (Statement state, Connection conn) {
40 if (state != null) {
41 try {
42 state.close();
43 } catch (SQLException e) {
44 e.printStackTrace();
45 }
46 }
47
48 if (conn != null) {
49 try {
50 conn.close();
51 } catch (SQLException e) {
52 e.printStackTrace();
53 }
54 }
55 }
56
57 public static void close (ResultSet rs, Statement state, Connection conn) {
58 if (rs != null) {
59 try {
60 rs.close();
61 } catch (SQLException e) {
62 e.printStackTrace();
63 }
64 }
65
66 if (state != null) {
67 try {
68 state.close();
69 } catch (SQLException e) {
70 e.printStackTrace();
71 }
72 }
73
74 if (conn != null) {
75 try {
76 conn.close();
77 } catch (SQLException e) {
78 e.printStackTrace();
79 }
80 }
81 }
82
83 }
//TheMain.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <meta charset="UTF-8">
7 <title>主页</title>
8 </head>
9 <style>
10 a:link {color:blue;}
11 a:visited {color:blue;}/*选择未访问、已访问、悬浮和活动链接,并设置它们的样式:*/
12 a:hover {color:red;}
13 a{
14 font-size:22px;
15 font-family:"楷体";/*设置字体*/
16 font-weight:2px;
17 }
18 h1 {
19 color:red;
20 font-size:44px;
21 }
22 </style>
23 <body >
24 <%
25 Object message = request.getAttribute("message");//放置一个字符串,并取出
26 if(message!=null && !"".equals(message)){
27
28 %>
29 <script type="text/javascript">
30 alert("<%=request.getAttribute("message")%>");
31 request.setAttribute("message", "");
32 </script>
33 <%} %>
34 <h1 align="center" >请选择下面其中一项</h1>
35 <a href="UserServlet?method=allall" style="text-decoration:none" ><h2 align="center">显示全部学生信息</h2></a>
36
37 <a href="zc.jsp" style="text-decoration:none" ><h2 align="center">增加学生信息</h2></a>
38
39 <a href="delete.jsp" style="text-decoration:none" ><h2 align="center">删除学生信息</h2></a>
40
41 <a href="updatesome.jsp" style="text-decoration:none" ><h2 align="center">修改学生信息</h2></a>
42
43 <a href="selectmore.jsp" style="text-decoration:none" ><h2 align="center">查找学生信息</h2></a>
44
45 <a href="UserServlet?method=paixu" style="text-decoration:none" ><h2 align="center">成绩排序</h2></a>
46 </body>
47 </html>
//checkall.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
4 <!DOCTYPE html>
5 <html>
6 <head>
7 <meta charset="UTF-8">
8 <title>全部信息</title>
9 </head>
10 <body >
11
12 <div align="center">
13 <h1 style="color: red;" align="center"> 所有成员信息列表</h1>
14 <table border="1px" cellspacing="0" cellpadding="5px">
15 <tr height="35px">
16 <td><h3 style="color: yellow;">学号</h3></td>
17 <td><h3 style="color: yellow;">姓名</h3></td>
18 <td><h3 style="color: yellow;">班级</h3></td>
19 <td><h3 style="color: yellow;">课程</h3></td>
20 <td><h3 style="color: yellow;">分数</h3></td>
21 </tr>
22 <tr height="35px">
23 <c:forEach items="${allthing}" var="item" >
24 <td>${item.id }</td>
25 <td>${item.name }</td>
26 <td>${item.clas }</td>
27 <td>${item.ke }</td>
28 <td>${item.score }</td>
29
30 </tr>
31 </c:forEach>
32 </table>
33 <a href="TheMain.jsp"><h2 align="center">点击此处返回主页面</h2></a>
34 </div>
35 </body>
36 </html>
//delete.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <meta charset="UTF-8">
7 <title>删除学生信息</title>
8 </head>
9 <body text="yellow" style="background: url(images/wen7.jpg); background-size:100%" >
10 <h2 align="center">请输入想要删除信息的用户名</h2>
11 <form action="UserServlet?method=deletecheck" onsubmit="return chackall()" method="post" >
12
13 <%
14 Object message = request.getAttribute("message");//放置一个字符串,并取出
15 if(message!=null && !"".equals(message)){
16
17 %>
18 <script type="text/javascript">
19 alert("<%=request.getAttribute("message")%>");
20 </script>
21 <%} %>
22
23 <table align="center">
24 <tr><td>名字:</td>
25 <td><input type="text" id="name4" name="name4" style=" border-color:Lime;border-radius:6px;" maxlength="12" value="" placeholder="请输入账户名" /></td>
26 <tr><td></td><td>
27 <input type="submit" value="删除此用户所有信息" style="background-color:CornflowerBlue;width:150px;height:25px;border-radius:4px;" ></td>
28 <a href="TheMain.jsp"><h3 align="center">点击此处回到主页面!!!!!!</h4></a>
29 <script type="text/javascript">
30
31 //重置按钮处添加onclick调用formReset %>
32 function checkZhanghao()
33 {
34 var zhanghao = document.getElementById("zhanghu4");
35 var zhanghao1=zhanghao.value;
36 var reg = /^[a-z][a-z0-9A-Z]{6}/;
37 var ref= /^[A-Z][a-z0-9A-Z]{6}/
38 if(reg.test(zhanghao1)||ref.test(zhanghao1)){
39 //符合规则
40 return true;
41 }else{
42 //不符合规则
43 alert('账户格式错误,应以英文字母开头并且7位及以上');
44 zhanghao.value = "";
45 zhanghao.focus();
46 return false;
47 }
48 }
49 function chackall() {
50 var zhanghu3=document.getElementById("zhanghu4");
51 if(zhanghu3.value=="")
52 {
53 alert("用户名不能为空");
54 zhanghu3.focus();
55 return false;
56 }
57 return true;
58 }
59 </script>
60
61 </table>
62 </form>
63 </body>
64 </html>
//delete1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body text="yellow" style="background: url(images/wen5.jpg); background-size:100%">
<%
Object message = request.getAttribute("message");//放置一个字符串,并取出
if(message!=null && !"".equals(message)){ %>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<h2 align="center">恭喜您删除消息成功!!!!!</h2>
<a href="TheMain.jsp"><h2 align="center">点击此处返回到主页面</h2></a>
</body>
</html>
//deletecheck2.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
4 <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
5 <!DOCTYPE html>
6 <html>
7 <head>
8 <meta charset="UTF-8">
9 <title>再次确定删除</title>
10 </head>
11 <style>
12 a:link {color:blue;}
13 a:visited {color:blue;}/*选择未访问、已访问、悬浮和活动链接,并设置它们的样式:*/
14 a:hover {color:red;}
15 a{
16 font-size:18px;
17 font-family:"楷体";/*设置字体*/
18 font-weight:2px;
19 }
20 h1{
21 color:red;
22 font-size:44px;
23 }
24 </style>
25 <body text="red" >
26 <div align="center">
27 <h1 style="color: red;" align="center"> 所有成员信息列表</h1>
28 <table width="900">
29 <tr>
30 <tr height="35px">
31 <td><h3 style="color: yellow;">学号</h3></td>
32 <td><h3 style="color: yellow;">姓名</h3></td>
33 <td><h3 style="color: yellow;">班级</h3></td>
34 <td><h3 style="color: yellow;">课程</h3></td>
35 <td><h3 style="color: yellow;">分数</h3></td>
36 </tr>
37 <tr height="35px">
38 <c:forEach items="${Thething1 }" var="item" >
39 <td>${item.id }</td>
40 <td>${item.name }</td>
41 <td>${item.clas }</td>
42 <td>${item.ke }</td>
43 <td>${item.score }</td>
44
45 <td><a href="UserServlet?method=delete&name=${item.name }" onclick="return check()">删除</a>
46
47 </c:forEach>
48 </tr>
49
50
51 </table>
52 <script type="text/javascript">
53 function check() {
54 if (confirm("真的要删除吗?")){
55 return true;
56 }else{
57 return false;
58 }
59 }
60 </script>
61
62 <a href="TheMain.jsp"><h2 align="center">点击此处返回主页面</h2></a>
63 </html>
//paixu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>成绩排序结果</title>
</head>
<body>
<div align="center">
<h1 style="color: red;" align="center"> 所有成员信息列表</h1>
<table border="1px" cellspacing="0" cellpadding="5px">
<tr height="35px">
<td><h3 style="color: yellow;">学号</h3></td>
<td><h3 style="color: yellow;">姓名</h3></td>
<td><h3 style="color: yellow;">班级</h3></td>
<td><h3 style="color: yellow;">课程</h3></td>
<td><h3 style="color: yellow;">分数</h3></td>
</tr>
<tr height="35px">
<c:forEach items="${things}" var="item" >
<td>${item.id }</td>
<td>${item.name }</td>
<td>${item.clas }</td>
<td>${item.ke }</td>
<td>${item.score }</td> </tr>
</c:forEach>
</table>
<a href="TheMain.jsp"><h2 align="center">点击此处返回主页面</h2></a>
</div>
</body>
</html>
//selectmore.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <meta charset="UTF-8">
7 <title>查找学生信息</title>
8
9 <script>
10 var i=1;
11 var j=1;
12 document.getElementById('number1').value=i;
13 document.getElementById('number2').value=j;
14 function demoDisplay(){
15 if(document.getElementById("p2").style.display=="none"){
16 i++;
17 j++;
18 document.getElementById("p2").style.display="inline";
19 document.getElementById('number1').value=i;
20 document.getElementById('number2').value=j;
21 // alert(i);
22 // alert(j);
23 return;
24 }else if(document.getElementById("p3").style.display=="none")
25 {
26 i++;
27 j++;
28 document.getElementById("p3").style.display="inline";
29 document.getElementById('number1').value=i;
30 document.getElementById('number2').value=j;
31 // alert(i);
32 // alert(j);
33 return;
34 }else if(document.getElementById("p4").style.display=="none")
35 {
36 i++;
37 j++;
38 document.getElementById("p4").style.display="inline";
39 document.getElementById('number1').value=i;
40 document.getElementById('number2').value=j;
41 // alert(i);
42 // alert(j);
43 return;
44 }else if(document.getElementById("p5").style.display=="none")
45 {
46 i++;
47 j++;
48 document.getElementById("p5").style.display="inline";
49 document.getElementById('number1').value=i;
50 document.getElementById('number2').value=j;
51 // alert(i);
52 // alert(j);
53 return;
54 }
55 }
56 function demoVisibility(){
57 if(document.getElementById("p5").style.display=="inline")
58 {
59 i--;
60 j--;
61 document.getElementById("p5").style.display="none";
62 document.getElementById('number1').value=i;
63 document.getElementById('number2').value=j;
64 //System.out.println("i:"+i+"j"+j);
65 return;
66 }else if(document.getElementById("p4").style.display=="inline")
67 {
68 i--;
69 j--;
70 document.getElementById("p4").style.display="none";
71 document.getElementById('number1').value=i;
72 document.getElementById('number2').value=j;
73 //System.out.println("i:"+i+"j"+j);
74 return;
75 }else if(document.getElementById("p3").style.display=="inline")
76 {
77 i--;
78 j--;
79 document.getElementById("p3").style.display="none";
80 document.getElementById('number1').value=i;
81 document.getElementById('number2').value=j;
82 //System.out.println("i:"+i+"j"+j);
83 return;
84 }else if(document.getElementById("p2").style.display=="inline")
85 {
86 i--;
87 j--;
88 document.getElementById("p2").style.display="none";
89 document.getElementById('number1').value=i;
90 document.getElementById('number2').value=j;
91 //System.out.println("i:"+i+"j"+j);
92 return;
93 }
94 }
95 </script>
96
97 </head>
98 <body>
99 <%
100 Object message=request.getAttribute("message");
101 if(message!=null&&!"".equals(message)){
102 %>
103
104 <script type="text/javascript">
105 alert("<%=request.getAttribute("message")%>");
106 </script>
107 <%}%>
108 <form action="Servlet" method="post">
109 <br>
110
111 <button type="button" onclick="demoDisplay()" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">+</i></button>
112 <button type="button" onclick="demoVisibility()" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">-</i></button><br>
113
114
115 <div id="p1">
116
117 <select name="g22" style="visibility:hidden">
118 <option value="且">且</option>
119 <option value="或">或</option>
120 </select>
121 <select name="s1" >
122 <option>学号</option>
123 <option>姓名</option>
124 <option>班级</option>
125 <option>课程</option>
126 <option>分数</option>
127 </select>
128 <input type="text" name="shuru1" value="" />
129 <select name="c1">
130 <option>精确</option>
131 <option>模糊</option>
132 </select>
133 <br>
134 </div>
135
136 <div id="p2" style="display:none">
137
138 <select name="g1" >
139 <option value="且">且</option>
140 <option value="或">或</option>
141 </select>
142 <select name="s2">
143 <option>学号</option>
144 <option>姓名</option>
145 <option>班级</option>
146 <option>课程</option>
147 <option>分数</option>
148 </select>
149 <input type="text" name="shuru2" value="" />
150 <select name="c2">
151 <option>精确</option>
152 <option>模糊</option>
153 </select>
154 <br>
155 </div>
156
157 <div id="p3" style="display:none">
158
159 <select name="g2">
160 <option value="且">且</option>
161 <option value="或">或</option>
162 </select>
163 <select name="s3">
164 <option>学号</option>
165 <option>姓名</option>
166 <option>班级</option>
167 <option>课程</option>
168 <option>分数</option>
169 </select>
170 <input type="text" name="shuru3" value="" />
171 <select name="c3">
172 <option>精确</option>
173 <option>模糊</option>
174 </select>
175 <br>
176 </div>
177
178 <div id="p4" style="display:none">
179
180 <select name="g3">
181 <option value="且">且</option>
182 <option value="或">或</option>
183 </select>
184 <select name="s4">
185 <option>学号</option>
186 <option>姓名</option>
187 <option>班级</option>
188 <option>课程</option>
189 <option>分数</option>
190 </select>
191 <input type="text" name="shuru4" value="" />
192 <select name="c4">
193 <option>精确</option>
194 <option>模糊</option>
195 </select>
196 <br>
197 </div>
198
199 <div id="p5" style="display:none">
200
201 <select name="g4">
202 <option value="且">且</option>
203 <option value="或">或</option>
204 </select>
205 <select name="s5">
206 <option>学号</option>
207 <option>姓名</option>
208 <option>班级</option>
209 <option>课程</option>
210 <option>分数</option>
211 </select>
212 <input type="text" name="shuru5" value="" />
213 <select name="c5">
214 <option>精确</option>
215 <option>模糊</option>
216 </select>
217 </div>
218 <p hidden>
219 <input type="text" value="1" id="number1" name="number1">
220 <input type="text" value="1" id="number2" name="number2">
221 </p>
222 <br>
223 <input type="submit" name="submit" value="查询" >
224 </form>
225 <br>
226 <h4 align="left">
227 <%-- 一共查询到了<span style="color:red"><%=list.size() %></span>条数据 --%>
228 </h4>
229 <table class="table table-striped">
230 <a href="TheMain.jsp"><h3 align="left">点击此处回到主页面!!!!!!</h4></a>
231 </table>
232
233 </body>
234 </html>
//updatesome.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <meta charset="UTF-8">
7 <title>修改学生信息</title>
8 </head>
9 <body >
10 <h2 align="center">请输入想要修改信息的用户名</h2>
11 <form action="UserServlet?method=look" onsubmit="return chackall()" method="post" >
12
13 <%
14 Object message = request.getAttribute("message");//放置一个字符串,并取出
15 if(message!=null && !"".equals(message)){
16
17 %>
18 <script type="text/javascript">
19 alert("<%=request.getAttribute("message")%>");
20 </script>
21 <%} %>
22
23 <table align="center">
24 <tr><td>姓名:</td><td><input type="text" id="name5" style=" border-color:Lime;border-radius:6px;" name="name5" maxlength="12" value="" placeholder="请输入账户名" /></td>
25 <tr><td></td><td><input type="submit" value="进行修改" style="background-color:CornflowerBlue;width:150px;height:25px;border-radius:4px;" ></td>
26 <a href="TheMain.jsp"><h3 align="center">点击此处回到主页面!!!!!!</h4></a>
27 <script type="text/javascript">
28
29 //重置按钮处添加onclick调用formReset %>
30 function checkZhanghao()
31 {
32 var zhanghao = document.getElementById("zhanghu3");
33 var zhanghao1=zhanghao.value;
34 var reg = /^[a-z][a-z0-9A-Z]{6}/;
35 var ref= /^[A-Z][a-z0-9A-Z]{6}/
36 if(reg.test(zhanghao1)||ref.test(zhanghao1)){
37 //符合规则
38 return true;
39 }else{
40 //不符合规则
41 alert('账户格式错误,应以英文字母开头并且7位及以上');
42 zhanghao.value = "";
43 zhanghao.focus();
44 return false;
45 }
46 }
47 function chackall() {
48 var zhanghu3=document.getElementById("zhanghu3");
49 if(zhanghu3.value=="")
50 {
51 alert("用户名不能为空");
52 zhanghu3.focus();
53 return false;
54 }
55 return true;
56 }
57 </script>
58
59 </table>
60 </form>
61 </body>
62 </html>
//updatesome1.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
2 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
3 <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
4 <!DOCTYPE html>
5 <html>
6 <head>
7 <meta charset="utf-8">
8 <title>再次确认修改</title>
9 </head>
10 <body >
11 <form action="UserServlet?method=update" method="post" onsubmit="return chackall()" >
12 <%
13 Object message = request.getAttribute("message");//放置一个字符串,并取出
14 if(message!=null && !"".equals(message)){
15
16 %>
17 <script type="text/javascript">
18 alert("<%=request.getAttribute("message")%>");
19 </script>
20 <%} %>
21
22 学号:<input type="text" id="id6" name="id6" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required"/><br><br>
23 姓名:<input type="text" id="name6" name="name6" style=" border-color:Lime;border-radius:6px;" value="${user3.name}" maxlength="12" /><br><br>
24 班级:<input type="text" id="clas6" name="clas6" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
25 课程:<input type="text" id="ke6" name="ke6" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
26 分数:<input type="text" id="score6" name="score6" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
27
28 <hr>
29
30 <input type="submit" value="确认修改">
31
32
33 <br/>
34 <br/>
35
36 <script type="text/javascript">
37 //重置按钮处添加onclick调用formReset %>
38 var num=0;
39
40 function doCheck(ctrl) {
41 if(ctrl.checked){
42 num++;
43 //window.alert("iNumChecked++" + iNumChecked);
44 } else {
45 num--;
46 //window.alert("iNumChecked--" + iNumChecked);
47 }
48 if (num> 4) {
49 ctrl.checked = false;
50 num--;
51 window.alert('最多可以选择六组进行比较');
52 }
53 }
54
55 function checkZhanghao()
56 {
57 var zhanghao = document.getElementById("zhanghu");
58 var zhanghao1=zhanghao.value;
59 var reg = /^[a-z][a-z0-9A-Z]{6}/;
60 var ref= /^[A-Z][a-z0-9A-Z]{6}/
61 if(reg.test(zhanghao1)||ref.test(zhanghao1)){
62 //符合规则
63 return true;
64 }else{
65 //不符合规则
66 alert('账户格式错误,应以英文字母开头并且7位及以上');
67 zhanghao.value = "";
68 zhanghao.focus();
69 return false;
70 }
71 }
72
73 function checkPassword()
74 {
75 var password = document.getElementById("psw");
76 if((password.value).length<8)
77 {
78 alert('密码应为8位英文或数字');
79 password.value="";
80 password.focus();
81 return false;
82 }
83 }
84
85 function checkId()
86 {
87 var id1 = document.getElementById("xuehao")
88 var id=id1.value;
89 //学号的正确形式
90 // var reg = /^[0-9a-zA-Z]{6}/;
91 if((id<"20180000")|| (id>"20189999"))
92 {
93 alert('学号格式不正确应以2018开头的八位数字,请重新填写!');
94 id1.value="";
95 id1.focus();
96 return false;
97 }
98 else{
99 //不符合规则
100 return true;
101 }
102 }
103
104
105 </script>
106
107
108
109 <script type="text/javascript">
110 function chackall() {
111 var sex=document.getElementById("sex");
112 var xueyuan=document.getElementById("xueyuan");
113 var name=document.getElementById("name");
114 var xi=document.getElementById("xi");
115 var class1=document.getElementById("class1");
116 var year=document.getElementById("year");
117 var sheng=document.getElementById("sheng");
118 var beizhu=document.getElementById("beizhu");
119 var mail=document.getElementById("mail");
120
121 if(sex.value=="")
122 {
123 alert("性别不能为空");
124 sex.focus();
125 return false;
126 }
127
128 if(name.value=="")
129 {
130 alert("名字不能为空");
131 name.focus();
132 return false;
133 }
134
135
136 if(mail.value=="")
137 {
138 alert("邮箱不能为空");
139 n.focus();
140 return false;
141 }
142
143 if(xueyuan.value=="")
144 {
145 alert("所在学院不能为空");
146 xueyuan.focus();
147 return false;
148 }
149
150 if(xi.value=="")
151 {
152 alert("所在系不能为空");
153 xi.focus();
154 return false;
155 }
156
157 if(class1.value=="")
158 {
159 alert("所在班级不能为空");
160 class1.focus();
161 return false;
162 }
163
164 if(year.value=="")
165 {
166 alert("入学年份不能为空");
167 year.focus();
168 return false;
169 }
170
171 if(sheng.value=="")
172 {
173 alert("生源地不能为空");
174 sheng.focus();
175 return false;
176 }
177
178 if(beizhu.value=="")
179 {
180 alert("备注不能为空");
181 beizhu.focus();
182 return false;
183 }
184
185
186 }
187
188 </script>
189 </form>
190 </body>
191 </html>
//updatesome2.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <meta charset="UTF-8">
7 <title>修改信息成功</title>
8 </head>
9 <body style="background: url(images/wen7.jpg); background-size:100%" text="yellow">
10 <%
11 Object message = request.getAttribute("message");//放置一个字符串,并取出
12 if(message!=null && !"".equals(message)){
13
14 %>
15 <script type="text/javascript">
16 alert("<%=request.getAttribute("message")%>");
17 </script>
18 <%} %>
19 <h2 align="center">恭喜您修改信息成功!!!!!</h2>
20 <h2 align="center"><a href="TheMain.jsp">点击此处回到主页面</a></h2>
21 </body>
22 </html>
//zc.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8"
2 pageEncoding="utf-8"%>
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <meta charset="utf-8">
7 <title>增加学生信息</title>
8 <style>
9 h3{
10 color:red;
11 font-size:15px;
12 }
13 </style>
14 </head>
15 <body >
16 <%--onsubmit="return chackall()" --%>
17 <form action="UserServlet?method=add" method="post" onsubmit="return chackall()" >
18 <%
19 Object message = request.getAttribute("message");//放置一个字符串,并取出
20 if(message!=null && !"".equals(message)){
21
22 %>
23 <script type="text/javascript">
24 alert("<%=request.getAttribute("message")%>");
25 </script>
26 <%} %>
27 学号:<input type="text" id="id" name="id" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
28 姓名:<input type="text" id="name" name="name" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
29 班级:<input type="text" id="clas" name="clas" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
30 课程:<input type="text" id="ke" name="ke" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
31 分数:<input type="text" id="score" name="score" style=" border-color:Lime;border-radius:6px;" maxlength="12" required="required" /><br><br>
32 <hr>
33 <input type="submit" value="添加">
34
35 <a href="TheMain.jsp"><h3 align="left">点击此处回到主页面!!!!!!</h4></a>
36 <br/>
37 <br/>
38 <%--
39 <script type="text/javascript">
40 //重置按钮处添加onclick调用formReset %>
41
42 function checkZhanghao()
43 {
44 var zhanghao = document.getElementById("zhanghu");
45 var zhanghao1=zhanghao.value;
46 var reg = /^[a-z][a-z0-9A-Z]{6}/;
47 var ref= /^[A-Z][a-z0-9A-Z]{6}/
48 if(reg.test(zhanghao1)||ref.test(zhanghao1)){
49 //符合规则
50 return true;
51 }else{
52 //不符合规则
53 alert('账户格式错误,应以英文字母开头并且7位及以上');
54 zhanghao.value = "";
55 zhanghao.focus();
56 return false;
57 }
58 }
59
60 function checkPassword()
61 {
62 var password = document.getElementById("psw");
63 if((password.value).length<8)
64 {
65 alert('密码应为8位英文或数字');
66 password.value="";
67 password.focus();
68 return false;
69 }
70 }
71
72 function checkId()
73 {
74 var id1 = document.getElementById("xuehao")
75 var id=id1.value;
76 //学号的正确形式
77 // var reg = /^[0-9a-zA-Z]{6}/;
78 if((id<"20180000")|| (id>"20189999"))
79 {
80 alert('学号格式不正确应以2018开头的八位数字,请重新填写!');
81 id1.value="";
82 id1.focus();
83 return false;
84 }
85 else{
86 //不符合规则
87 return true;
88 }
89 }
90
91
92 </script>--%>
93
94
95
96 <script type="text/javascript">
97 var num=0;
98
99
100 function doCheck(ctrl) {
101 if(ctrl.checked)
102 {
103 num++;
104 }
105 else
106 {
107 num--;
108 }
109 if (num> 4)
110 {
111 ctrl.checked = false;
112 num--;
113 window.alert('最多可以选择4组进行比较');
114 }
115 }
116
117
118
119
120
121
122 <%--
123 var name=document.getElementById("name");
124 var sex=document.getElementById("sex");
125 var minzu=document.getElementById("minzu");
126 var time=document.getElementById("time");
127 var age=document.getElementById("age");
128 var zhengzhi=document.getElementById("zhengzhi");
129 var fuwu=document.getElementById("fuwu");
130
131 if(name.value=="")
132 {
133 alert("名字不能为空");
134 name.focus();
135 return false;
136 }
137
138 if(sex.value=="")
139 {
140 alert("性别不能为空");
141 sex.focus();
142 return false;
143 }
144
145
146 if(minzu.value=="")
147 {
148 alert("民族不能为空");
149 minzu.focus();
150 return false;
151 }
152
153 if(time.value=="")
154 {
155 alert("时间不能为空");
156 time.focus();
157 return false;
158 }
159
160 if(age.value=="")
161 {
162 alert("年龄不能为空");
163 age.focus();
164 return false;
165 }
166
167 if(zhengzhi.value=="")
168 {
169 alert("政治面目不能为空");
170 zhengzhi.focus();
171 return false;
172 }
173 if(fuwu.value=="")
174 {
175 alert("服务不能为空");
176 fuwu.focus();
177 return false;
178 }
179 --%>
180 function chackall() {
181 var a=document.getElementsByName('fuwu');
182 var b=0; //设定一个初始值
183 for(var i=0;i<a.length;i++)
184 {
185
186 if(a[i].checked==true)
187 {
188 return true;
189 }
190 else
191 {
192 if(a[i].checked==false)
193 {
194 b++; //如果方框没选中,该值会累加
195 }
196 if(b==a.length) //如果该值和方框的个数相同,那么就会报错
197 {
198 alert('服务类型最少选一个,最多选四个,请重新操作');
199 return false;
200 }
201 }
202 }
203 }
204
205
206
207
208 </script>
209 </form>
210
211 </body>
212 </html>
//zc2.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <meta charset="UTF-8">
7 <title>添加用户成功</title>
8 </head>
9 <body style="background: url(images/wen7.jpg); background-size:100%" text="yellow">
10 <h2 align="center">恭喜您添加用户成功</h2>
11 <a href="zc.jsp"><h3 align="center">点击此处回到添加页面!!!!!!</h4></a>
12 <a href="Themain.jsp"><h3 align="center">点击此处回到主页面!!!!!!</h4></a>
13 </body>
14 </html>
3、感谢你的观看,有什么问题或者不懂的请你评论在下方,或者联系我,会很耐心的为你解答。我们一起加油!!!!
java web简单的增删改查的更多相关文章
- Java web 简单的增删改查程序(超详细)
就是简单的对数据进行增删改查.代码如下: 1.bean层:用来封装属性及其get set方法 toString方法,有参构造方法,无参构造方法等. public class Bean { privat ...
- java web数据库的增删改查详细
本次课上实验是完成数据库的增删改查. 包括增加用户信息.删除用户信息.多条件查找用户信息.修改用户信息(主要是复选框单选框等的相关操作.) 下面下看一下各个界面的样子. 总页面:显示全部页面:增加页面 ...
- Java实现简单的增删改查操作
需求分析:通过数组 ,完成 对学生信息的 管理 (增删改查)创建1个 学生类创建1个 CRUD的类 – 学生管理类 并测试 在这个程序中我只运用了两个类进行操作 package com.hopu.de ...
- JAVA JDBC 简单的增删改查
package jdbc_util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepar ...
- salesforce 零基础学习(五十一)使用 Salesforce.com SOAP API 实现用户登录以及简单的增删改查(JAVA访问salesforce)
此篇请参看:https://resources.docs.salesforce.com/202/latest/en-us/sfdc/pdf/salesforce_developer_environme ...
- 通过flask实现web页面简单的增删改查bootstrap美化版
通过flask实现web页面简单的增删改查bootstrap美化版 项目目录结构 [root@node1 python]# tree -L 2 . ├── animate.css ├── fileut ...
- 通过flask实现web页面简单的增删改查
通过flask实现web页面简单的增删改查 # 1.后台程序falsk_web01.py #coding:utf-8 from flask import Flask,render_template,r ...
- ElasticSearch6(三)-- Java API实现简单的增删改查
基于ElasticSearch6.2.4, Java API创建索引.查询.修改.删除,pom依赖和获取es连接 可查看此文章. package com.xsjt.learn; import java ...
- Java通过JDBC进行简单的增删改查(以MySQL为例)
Java通过JDBC进行简单的增删改查(以MySQL为例) 目录: 前言:什么是JDBC 一.准备工作(一):MySQL安装配置和基础学习 二.准备工作(二):下载数据库对应的jar包并导入 三.JD ...
随机推荐
- sort(hdu oj 1425)计数排序和快速排序
Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0 < n,m < 1000000),第二行包含n个各不 ...
- 众所周知,B站并不是个学习网站
立了一个Flag鸽鸽鸽鸽 我喜立Flag,9月份说要做点视频,不知不觉已经鸽了俩月了.中间就零星时间学了一些剪辑方面的知识,工作太忙,视频一直没有实质进展.视频的灵魂其实是脚本,到现在还没写好.我还是 ...
- Mac系统使用Parallels Desktop安装Win10
1.Parallels Desktop破解版下载 2.原版Windows 10 2004 X64位 (原版安装)2020 11 Windows 系统镜像必须为原版,ghost版不行.亲测ghost版本 ...
- a标签中的target
html中target四种选择_blank._parent._self._top,分别是什么意思? eg:<Cell title="Open link in new window&qu ...
- 上周我面了个三年 Javaer,这几个问题都没答出来
身为 Java Web 开发我发现很多人一些 Web 基础问题都答不上来. 上周我面试了一个三年经验的小伙子,一开始我问他 HTTP/1.HTTP/2相关的他到是能答点东西出来. 后来我问他:你知道 ...
- pip install 一个本地包时提示error: Microsoft Visual C++ 14.0 is required.
错误如下: error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Too ...
- [大雾雾雾雾] 告别该死的 EFCore Fluent API (续)
朋友们好啊, 我是 .NET 打工人 玩双截棍的熊猫 刚才有个朋友问我 猫猫发生什么事了 我说 怎么回事? 给我发了一张截图 我一看!嗷!原来是zuo天有两个数据库, 一个四十多岁,一个三十多岁 它们 ...
- Java基础教程——UDP编程
UDP:User Datagram Protocol,用户数据报协议 服务端: import java.net.*; import java.io.*; public class UdpServer ...
- 【对不起】我并不是真的会用spring
19年12月4日,为了测试另外一个部门的服务在注册到这边zk后能否拿到dubbo代理,在controller草草写了一个http服务请求之,发现所有的dubbo接口都没有被注入代理,排查许久之后,发现 ...
- 笔记本无法连接校园网,windows诊断显示校园网之未响应
打开cmd(管理员): 输入以下四条,每一条都按enter ipconfig /flushdns ipconfig /registerdns ipconfig /release ipconfig / ...