基于javaweb的JSP+Servlet晚会抽奖系统(java+jdbc+servlet+ajax+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

030023062402

040023062402

050023062402

060023062402

070023062402

080023062402

基于javaweb的JSP+Servlet晚会抽奖系统(java+jdbc+servlet+ajax+mysql)

一、项目运行 环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

Jdbc+ Servlert + html+ css + JavaScript + JQuery + Ajax +等等

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
		this.num = num;
}
}
package ajaxtest;

public class luck_dog {
private int id;
private int luck_num;
private int luck_group;

public int getLuck_group() {
return luck_group;
}

public void setLuck_group(int luck_group) {
this.luck_group = luck_group;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getLuck_num() {
return luck_num;
}

public void setLuck_num(int luck_num) {
this.luck_num = luck_num;
}
}
package ajaxtest;



public class ajax {

public void ajaxtest(){
try {
String s = "{\"name\":\"张三\",\"age\":\"20\"}";

ServletActionContext.getResponse().setCharacterEncoding("UTF-8");
ServletActionContext.getResponse().getWriter().print(s);
} catch (IOException e) {
e.printStackTrace();
}
}

}
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
				}
}
} catch (Exception e) {
// TODO: handle exception
} finally {
dbManager.closeConnection();

}

}

public void view_result() {
System.out.println("view_resultview_resultview_result");
DBManager dbManager = new DBManager();
String sql = "select * from lucky_dog";
luck_dog luck_dog = null;
ResultSet resultSet = dbManager.executeQuery(sql);
List<luck_dog> luck_dogList = new ArrayList<luck_dog>();
try {
while (resultSet.next()) {
luck_dog = new luck_dog();
luck_dog.setId(resultSet.getInt("id"));
luck_dog.setLuck_group(resultSet.getInt("luck_group"));
luck_dog.setLuck_num(resultSet.getInt("luck_num"));
luck_dogList.add(luck_dog);
}
JSONArray jsonArray = JSONArray.fromObject(luck_dogList);
System.out.println(jsonArray);
// String s = "{\"name\":\"提示\",\"age\":\"已提交抢答申请,请静候抢答结果!!!\"}";
ServletActionContext.getResponse().setCharacterEncoding("UTF-8");
ServletActionContext.getResponse().getWriter().print(jsonArray);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
dbManager.closeConnection();

}

}

}
package ajaxtest;

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
public static Connection getConnnection() {
Connection connection = null;
String dbClassName = "com.mysql.jdbc.Driver";
String dbUrl = "jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true";
String dbUser = "root";
String dbPwd = "123456";
try {
Class.forName(dbClassName);
connection = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
} catch (Exception e) {
System.err.println("connect失败");
e.printStackTrace();
}
return connection;
}

public boolean deleteSQL(String sqlString) {
try {
prst = getConnnection().prepareStatement(sqlString);
//prst.setString(1, parameter);
prst.execute();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("");
return false;
}
}

public boolean deleteSQL(String sqlString, String parameter) {
try {
prst = getConnnection().prepareStatement(sqlString);
prst.setString(1, parameter);
return prst.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("");
return false;
}
}

public boolean insertSQL(String sqlString) {
try {
prst = getConnnection().prepareStatement(sqlString);
prst.execute();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("insert出错");
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
package ajaxtest;

public class admin {
private String username;
private String password;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<c:if test="${sessionScope.admin==null }" >
<meta http-equiv="refresh" content="0;url=admin_login.jsp">
</c:if>

<title>2022年计算机与信息学院迎新年晚会暨师生交流会</title>

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
    }
return true;
}

public boolean executeUpdate(String sql, String parameter1, String parameter2, String parameter3) {
try {
prst = getConnnection().prepareStatement(sql);
prst.setString(1, parameter1);
prst.setString(2, parameter2);
prst.setString(3, parameter3);
prst.execute();
} catch (SQLException e) {

e.printStackTrace();
return false;
}
return true;
}

public boolean executeUpdate(String sql, String parameter1, String parameter2, int parameter3) {
try {
prst = getConnnection().prepareStatement(sql);
prst.setString(1, parameter1);
prst.setString(2, parameter2);
prst.setInt(3, parameter3);
prst.execute();
} catch (SQLException e) {

e.printStackTrace();
return false;
}
return true;
}

public boolean executeUpdate(String sql, String parameter1, String parameter2, String parameter3, String parameter4) {
try {
prst = getConnnection().prepareStatement(sql);
prst.setString(1, parameter1);
prst.setString(2, parameter2);
prst.setString(3, parameter3);
prst.setString(4, parameter4);
prst.execute();
} catch (SQLException e) {

e.printStackTrace();
return false;
}


项目链接:
https://javayms.github.io?id=531422282105200dw
https://javayms.pages.dev?id=531422282105200dw