首页 > 编程语言 >校园社团活动管理系统java

校园社团活动管理系统java

时间:2022-11-09 21:11:06浏览次数:40  
标签:didian java String 管理系统 req zhuti bean 社团活动 public

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>

  

标签:didian,java,String,管理系统,req,zhuti,bean,社团活动,public
From: https://www.cnblogs.com/LvJinshuai/p/16875185.html

相关文章

  • JavaScript函数
     JavaScript函数JavaScript函数概念    可以储存一段代码的数据类型- 分为两个阶段:函数定义阶段和函数调用阶段- 1.函数定义阶段:把代码放进“盒子”,函数里面代......
  • Java——语句:空语句、复合语句、表达式语句
                                                        ......
  • Head First Java 读书笔记
    第10章:数字与静态性Math有什么特点?在Java中没有东西是全局(global)的。但,Math方法是接近全局的方法。Math不能用来创建实例变量。因为Math是用来执行数据计算的,所以......
  • java的反射
    packagecom.tedu.day16;importcom.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;importjava.lang.reflect.Constructor;importjava.lang.reflect.Field......
  • SpringBoot 01: JavaConfig + @ImportResource + @PropertyResource
    springboot的前置知识:通过注解创建对象和读取配置文件1.JavaConfig设计思想使用java类作为xml配置文件的替代,是配置spring容器的纯java的方式可以创建java对象并把......
  • javascript初识以及总结
    今天主要学习了js的概述,书写的三种位置(和css一样内嵌外联和内联三种)以及变量的定义,变量的定义用的是var来定义的并且学了五种数据类型 有number数值型strin......
  • 房产信息管理系统--查询房产信息
    查询房产信息:可以按照户型、地址、建造年份、建造面积,销售报价五个条件进行综合查询,查询结果以列表形式显示,显示结果信息包括序号、地址、销售报价,点击地址,可以查看该套房......
  • 房产信息管理系统--浏览房产信息
    浏览房产信息:顾客登录后,可以查看所有在售房产信息;房产经纪人登录后,只能查看系统管理员授权的房产信息;系统管理员登录后可以查看全部房产信息(四种房产状态)。(3分) 顾客浏览:......
  • Java并发编程一ThreadLocal初使用
    推荐:​​Java并发编程汇总​​Java并发编程一ThreadLocal初使用任务为了方便使用以及展现​​ThreadLocal​​​的优点,这里首先给出一个任务,然后不断地去加大任务难度,再根据......
  • Java并发编程一引用类型、升级类型原子类初使用加源码分析
    推荐:​​Java并发编程汇总​​Java并发编程一引用类型、升级类型原子类初使用加源码分析首先我们来看一看有哪些原子类。现在我们来看看该如何去使用这些引用类型、升级类......