校园社团活动管理系统java
package Bean;
public class Bean1 {
private String zhuti;
private String mudi;
private String leixing;
private String shijian;
private String didian;
private String duixiang;
private String neirong;
private String anpai;
public String getZhuti() {
return zhuti;
}
public void setZhuti(String zhuti) {
this.zhuti = zhuti;
}
public String getMudi() {
return mudi;
}
public void setMudi(String mudi) {
this.mudi = mudi;
}
public String getLeixing() {
return leixing;
}
public void setLeixing(String leixing) {
this.leixing = leixing;
}
public String getShijian() {
return shijian;
}
public void setShijian(String shijian) {
this.shijian = shijian;
}
public String getDidian() {
return didian;
}
public void setDidian(String didian) {
this.didian = didian;
}
public String getDuixiang() {
return duixiang;
}
public void setDuixiang(String duixiang) {
this.duixiang = duixiang;
}
public String getNeirong() {
return neirong;
}
public void setNeirong(String neirong) {
this.neirong = neirong;
}
public String getAnpai() {
return anpai;
}
public void setAnpai(String anpai) {
this.anpai = anpai;
}
/*@Override
public String toString() {
return "Bean1 [zhuti=" + zhuti + ", mudi=" + mudi + ", leixing=" + leixing + ", shijian=" + shijian
+ ", didian=" + didian + ", duixiang=" + duixiang + ", neirong=" + neirong + ", anpai=" + anpai
+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString()
+ "]";
}*/
public Bean1(String zhuti, String mudi, String leixing, String shijian, String didian, String duixiang, String neirong, String anpai) {
this.zhuti=zhuti;
this.mudi=mudi;
this.leixing=leixing;
this.shijian=shijian;
this.didian=didian;
this.duixiang=duixiang;
this.neirong=neirong;
this.anpai=anpai;
//super();
// TODO Auto-generated constructor stub
}
}
package Dao;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import Bean.Bean1;
import Util.Util1;
public class Dao1 {
public static int add(Bean1 bean)
{
String sql = "insert into 校园社团活动管理系统(zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai) values('" +bean.getZhuti() + "','" + bean.getMudi() + "','" +bean.getLeixing() + "','"+bean.getShijian() + "','"+bean.getDidian() + "','"+bean.getDuixiang() + "','"+ bean.getNeirong() + "','" +bean.getAnpai()+"')";
Connection conn = Util1.getConn();
Statement state = null;
int count=0;
try {
state = conn.createStatement();
count = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
Util1.close(state, conn);
}
return count;
}
public static int update(Bean1 bean)
{
String sql = "update 校园社团活动管理系统 set mudi='" + bean.getMudi() + "', leixing='" + bean.getLeixing() +"', shijian='" + bean.getShijian() +"', didian='" + bean.getDidian() +"', duixiang='" + bean.getDuixiang() +"', neirong='" + bean.getNeirong() + "', anpai='" + bean.getAnpai()
+ "' where zhuti='" + bean.getZhuti() + "'";
Connection conn = Util1.getConn();
Statement state = null;
int count=0;
try {
state = conn.createStatement();
count = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
Util1.close(state, conn);
}
return count;
}
public static int delete (String t) {
int count=0;
String sql = "delete from 校园社团活动管理系统 where zhuti='" + t + "'";
System.out.println(sql);
Connection conn = Util1.getConn();
Statement state = null;
try {
state = conn.createStatement();
count = state.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
Util1.close(state, conn);
}
return count;
}
}
package Util;
import java.sql.*;
public class Util1 {
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/demo?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
static final String USER = "root";
static final String PASS = "123456";
public static Connection getConn () {
Connection conn = null;
try {
Class.forName(JDBC_DRIVER);
System.out.println("连接数据库...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void close (Statement state, Connection conn) {
if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void close (ResultSet rs, Statement state, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
package servlet;
import java.sql.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Bean.Bean1;
import service.Service;
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Service service=new Service();
/**
* @see HttpServlet#HttpServlet()
*/
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
if ("add".equals(method))
{
try {
add(req, res);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if ("update".equals(method))
{
try {
update(req, res);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if ("delete".equals(method))
{
try {
delete(req, res);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
// TODO Auto-generated method stub
req.setCharacterEncoding("utf-8");
String zhuti = req.getParameter("zhuti");
int i =service.delete(zhuti);
if(i>0) {
req.setAttribute("message", "删除成功!");
req.getRequestDispatcher("shanchu.jsp").forward(req,resp);
} else {
req.setAttribute("message", "删除失败!");
req.getRequestDispatcher("shanchu.jsp").forward(req,resp);
}
}
private void add(HttpServletRequest req, HttpServletResponse res) throws Exception {
req.setCharacterEncoding("utf-8");
String zhuti = req.getParameter("zhuti");
String mudi = req.getParameter("mudi");
String leixing = req.getParameter("leixing");
String shijian = req.getParameter("shijian");
String didian = req.getParameter("didian");
String duixiang = req.getParameter("duixiang");
String neirong = req.getParameter("neirong");
String anpai = req.getParameter("anpai");
//people people = new people(hu_bie,zhu_fang_lei_bie,name,idc,min_zu,jiao_yu,sex,S,N);
Bean1 bean=new Bean1(zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai);
//添加后消息显示
if(service.add(bean)>0) {
req.setAttribute("message", "添加成功");
req.getRequestDispatcher("add.jsp").forward(req,res);
} else {
req.setAttribute("message", "添加失败,请重新录入");
req.getRequestDispatcher("add.jsp").forward(req,res);
}
}
private void update(HttpServletRequest req, HttpServletResponse res) throws Exception {
req.setCharacterEncoding("utf-8");
String zhuti = req.getParameter("zhuti");
String mudi = req.getParameter("mudi");
String leixing = req.getParameter("leixing");
String shijian = req.getParameter("shijian");
String didian = req.getParameter("didian");
String duixiang = req.getParameter("duixiang");
String neirong = req.getParameter("neirong");
String anpai = req.getParameter("anpai");
//people people = new people(hu_bie,zhu_fang_lei_bie,name,idc,min_zu,jiao_yu,sex,S,N);
Bean1 bean=new Bean1(zhuti,mudi,leixing,shijian,didian,duixiang,neirong,anpai);
//添加后消息显示
if(service.update(bean)>0) {
req.setAttribute("message", "修改成功");
req.getRequestDispatcher("xiugai.jsp").forward(req,res);
} else {
req.setAttribute("message", "修改失败,请重新录入");
req.getRequestDispatcher("xiugai.jsp").forward(req,res);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package service;
import Bean.Bean1;
import Dao.Dao1;
public class Service {
public int add(Bean1 bean)
{
if(Dao1.add(bean)>0)
{
return 1;
}
else
{
return 0;
}
}
public int update(Bean1 bean)
{
if(Dao1.update(bean)>0)
{
return 1;
}
else
{
return 0;
}
}
public int delete(String zhuti) {
if(Dao1.delete(zhuti)>0)
{
return 1;
}
return 0;
}
}
Screen.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">
<form name="form" method="post" action="add.jsp">
<input type="submit" value="发布活动信息">
</form>
<form name="form" method="post" action="xiugai.jsp">
<input type="submit" value="修改活动信息">
</form>
<form name="form" method="post" action="shanchu.jsp">
<input type="submit" value="删除活动信息">
</form>
<form name="form" method="post" action="chaxun.jsp">
<input type="submit" value="查询活动信息">
</form>
<form name="form" method="post" action="liulan.jsp">
<input type="submit" value="活动信息浏览">
</form>
</div>
</body>
</html>
add.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>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%}
%>
<div align="center">
<h1 style="color: black;">校园社团活动管理系统</h1>
<a href="Screen.jsp">返回主页</a>
<form name="form1" action="Servlet?method=add" method="post" onsubmit="return check()">
活动主题
<input type="text" name="zhuti"required pattern="^[\u4e00-\u9fa5]{1,20}"/>
<br>
活动目的
<input type="text" name="mudi"required pattern="^[\u4e00-\u9fa5]{1,50}"/><br>
活动类型
<td>
<input type="radio" name="leixing" value="社团竞赛" >社团竞赛
<input type="radio" name="leixing" value="野外采风" >野外采风<br>
<input type="radio" name="leixing" value="校内集会" >校内集会
<input type="radio" name="leixing" value="社团纳新" >社团纳新
</td><br>
活动时间
<input type="text" name="shijian"><br>
活动地点
<input type="text" name="didian"><br>
活动对象
<tr>
<td>
<input type="checkbox" name="duixiang" value="社团成员">社团成员
<input type="checkbox" name="duixiang" value="全体学生">全体学生
</td>
</tr>
<br>
活动内容
<input type="text" name="neirong"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
活动日程安排
<input type="text" name="anpai"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
<input type="submit" value="添加">
<input type="reset" value="重置"><br>
<div >
</body>
</html>
liulan.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Bean.Bean1" %>
<%@ page import="Dao.Dao1" %>
<%@ page import="Util.Util1" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>社团活动浏览</title>
</head>
<body>
<div align="center">
<form name="form" method="post" action="Screen.jsp">
<input type="submit" value="返回主页">
</form>
<table align="center" border="1" width="500">
<tr>
<th>活动主题</th>
<th>活动目的</th>
<th>活动类型</th>
<th>活动时间</th>
<th>活动地点</th>
<th>对象</th>
<th>活动内容</th>
<th>活动安排</th>
</tr>
<%
String sql = "SELECT * FROM `校园社团活动管理系统`";
Connection conn = Util1.getConn();
Statement state = null;
ResultSet rs = null;
Bean1 tbean=null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
String zhuti = rs.getString("zhuti");
String mudi = rs.getString("mudi");
String leixing = rs.getString("leixing");
String shijian = rs.getString("shijian");
String didian = rs.getString("didian");
String duixiang = rs.getString("duixiang");
String neirong = rs.getString("neirong");
String anpai = rs.getString("anpai");
out.println("<tr>"+"<td>"+zhuti+"</td>");
out.println("<td>"+mudi+"</td>");
out.println("<td>"+leixing+"</td>");
out.println("<td>"+shijian+"</td>");
out.println("<td>"+didian+"</td>");
out.println("<td>"+duixiang+"</td>");
out.println("<td>"+neirong+"</td>");
out.println("<td>"+anpai+"</td>"+"</tr>");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
Util1.close(rs, state, conn);
}
%>
</body>
</html>
shanchu.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">
<form name="form" method="post" action="Screen.jsp">
<input type="submit" value="返回主页">
</form>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<form action="Servlet?method=delete" method="post" onsubmit="return check()">
请重新输入删除的主题
<input type="text" name="zhuti" />
<input type="submit" value="删除" />
</body>
</html>
xiugai.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>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%}
%>
<div align="center">
<h1 style="color: black;">校园社团活动管理系统</h1>
<a href="Screen.jsp">返回主页</a>
<form name="form1" action="Servlet?method=update" method="post" onsubmit="return check()">
活动主题
<input type="text" name="zhuti"required pattern="^[\u4e00-\u9fa5]{1,20}"/>
<br>
活动目的
<input type="text" name="mudi"required pattern="^[\u4e00-\u9fa5]{1,50}"/><br>
活动类型
<td>
<input type="radio" name="leixing" value="社团竞赛" >社团竞赛
<input type="radio" name="leixing" value="野外采风" >野外采风<br>
<input type="radio" name="leixing" value="校内集会" >校内集会
<input type="radio" name="leixing" value="社团纳新" >社团纳新
</td><br>
活动时间
<input type="text" name="shijian"><br>
活动地点
<input type="text" name="didian"><br>
活动对象
<tr>
<td>
<input type="checkbox" name="duixiang" value="社团成员">社团成员
<input type="checkbox" name="duixiang" value="全体学生">全体学生
</td>
</tr>
<br>
活动内容
<input type="text" name="neirong"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
活动日程安排
<input type="text" name="anpai"required pattern="^[\u4e00-\u9fa5]{1,500}"/><br>
<input type="submit" value="修改">
<input type="reset" value="重置"><br>
<div >
</body>
</html>
浙公网安备 33010602011771号