校园社团活动管理系统(20分)
1、项目需求:
校园社团作为高校课外活动的重要组成部分,发展十分迅速,也受到越来越多学生的欢迎,社团规模、数量等都在日益增长,社团活动也更为多样和丰富。然而,大多数高校还没有一个完整成熟的社团管理系统,仅仅是靠人力来管理,导致效率低下,而学生也只能通过线下或者公众号的方式了解社团,另外,社团活动的通知方式也很杂乱,并没有一个信息聚合、消息发布的平台。
因此,高校有必要建立一个校园社团管理系统,使得社团管理工作规范化、系统化、程序化、科学化,提高管理工作的效率。
2.系统要求与功能设计
2.1 页面功能要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(1分)
(2)网站页面整体风格统一;
图1 活动普查系统功能结构图
(3)主页面:要求显示发布活动信息、修改活动信息、删除活动信息、查询活动信息,活动信息浏览五个子菜单。(1分)
(4)发布活动信息页面:(6分)
①完成添加活动信息发布,基本信息和填报限制如下表所示
活动主题 |
字符串(不超过20个汉字) |
活动目的 |
字符串(不超过50个汉字) |
活动类型 |
社团竞赛、野外采风、校内集会、社团纳新(单选框) |
活动时间 |
文本框 |
活动地点 |
文本框 |
活动对象 |
社团成员、全体学生(复选框实现) |
活动内容 |
(文本框,不超过500个汉字) |
活动日程安排 |
(文本框,不超过500个汉字) |
②点击“提交”按钮,保存成功则跳转到活动基本信息浏览界面,新录入的信息置顶显示。失败则提示错误信息,返回当前页面
评分标准:
① 完成活动信息发布页面(未完成0分,完成1分)
② 保存活动信息入库(未完成0分,完成1分)
③ 社团竞赛、野外采风、校内集会、社团纳新实现单选框录入1分。(未完成0分,全部完成1分)
④ 实现活动对象复选框录入1分。(未完成0分,完成1分)
⑤ 实现活动主题、活动目的、活动内容、活动日程安排的字数判断,实现三个以上得1分(未完成0分,完成1分)
⑥提交后页面跳转功能;(未完成0分,完成1分)
(5)修改活动信息页面:(3分)
输入活动主题,显示其余信息,可对活动目的、活动类型、活动时间、活动地点、活动对象、活动内容、活动日程安排进行修改。(活动目的、活动类型、活动时间、活动地点、活动对象、活动内容、活动日程安排必须符合录入要求);如果该活动主题数据库不存在,则提示“该活动不存在”。(3分)
评分标准:
① 完成修改活动信息页面(未完成0分,完成1分)
② 实现数据库中信息更新(未完成0分,完成1分)
③输入活动主题,显示其余信息,若该信息不存在,提示错误信息;(未完成0分,完成1分)
(6)删除活动信息页面:录入活动主题,显示详细信息后,点击“删除”按钮,弹出提示框,提示“是否确认删除该活动信息”,确认后删除该信息。(1分)
评分标准:
① 输入活动主题可显示其余信息。(未完成0分,完成0.5分)
②对应删除数据库中信息(未完成0分,完成0.5分)
(7)浏览活动信息页面:(2分)
以列表形式显示活动基本信息,结果列表中显示活动主题、活动时间,活动类型、活动对象基本信息,点击主题,可以跳转到活动详细信息,显示全部活动信息。
① 实现以列表形式显示活动基本信息,结果列表中显示活动主题、活动时间,活动类型、活动对象基本信息(未完成0分,完成1分)
②实现跳转活动详细信息页面,显示全部活动信息。(未完成0分,完成1分)
(8)查询活动信息页面:(3分)
要求根据活动主题、活动时间、活动类型、活动地点四种条件实现模糊查询,输出结果以列表形式显示,显示显示活动主题、活动时间,活动类型、活动对象基本信息,点击列表中的活动主题,跳转到活动详细信息页面。
评分标准:
①缺少一种查询条件扣除1分。(未完成0分,完成3分)
2.2 功能要求
(1)设计出合理的数据库和数据表,要求使用mysql、sqlserver、oracle三种数据库中一种(1分)
(2)使用Serverlet实现页面交互(1分)。
(3)使用Java Bean封装数据库连接操作(1分。)
DBUtil.java //返回conn
package DBUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
private static String url="jdbc:mysql://localhost:3306/数据库名称?serverTimezone=UTC";
private static String user="root";
private static String password="密码";
private static String jdbcName="com.mysql.cj.jdbc.Driver";
public static Connection getConnection() {
Connection con=null;
try {
Class.forName(jdbcName);
con=DriverManager.getConnection(url, user, password);
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
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();
}
}
}
}
Message.java
package Message;
public class Message {
String theme;
String purpose;
String type;
String time;
String place;
String object;
String content;
String arrange;
public Message(String theme, String purpose, String type, String time, String place, String object, String content,
String arrange) {
super();
this.theme = theme;
this.purpose = purpose;
this.type = type;
this.time = time;
this.place = place;
this.object = object;
this.content = content;
this.arrange = arrange;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
public String getPurpose() {
return purpose;
}
public void setPurpose(String purpose) {
this.purpose = purpose;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public String getObject() {
return object;
}
public void setObject(String object) {
this.object = object;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getArrange() {
return arrange;
}
public void setArrange(String arrange) {
this.arrange = arrange;
}
}
Service.java //执行操作sql语句的部分
package Service;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import DBUtil.DBUtil;
import Message.Message;
public class Service {
public boolean insert(Message message) throws SQLException{
String sql="insert into club(theme,purpose,type,time,place,object,content,arrange) values('"+message.getTheme()+"','"+message.getPurpose()+"','"+message.getType()+"','"+message.getTime()+"','"+message.getPlace()+"','"+message.getObject()+"','"+message.getContent()+"','"+message.getArrange()+"')";
Connection conn=null;//添加数据库,加载驱动
Statement state=null;//创建statement对象并置空
try {
conn=DBUtil.getConnection();
//实例化statement对象 方便操作
state=conn.createStatement();
System.out.println(sql);
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
DBUtil.close(state, conn);//close 释放资源
}
return true;
}
public boolean delete(String theme) throws SQLException{
String sql="delete from club where theme='"+theme+"' ";
Connection conn =DBUtil.getConnection();
Statement state=null;
try {
state=conn.createStatement();
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DBUtil.close(state, conn);
}
return false;
}
public boolean update(Message message) throws SQLException {
String sql="update club set purpose='"+message.getPurpose()+"',type='"+message.getType()+"',time='"+message.getTime()+"',place='"+message.getPlace()+"',object='"+message.getObject()+"',content='"+message.getContent()+"',arrange='"+message.getArrange()+"' where theme='"+message.getTheme()+"' ";
Connection conn=DBUtil.getConnection();
Statement state=null;
try {
state=conn.createStatement();
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DBUtil.close(state, conn);
}
return false;
}
public List<Message> selectByTheme(String theme1) throws SQLException {
//插入sql 语句
String sql="select * from club where theme like '%"+theme1+"%'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
//按姓名查
public List<Message> selectByTime(String time1) throws SQLException {
//插入sql 语句
String sql="select * from club where time = '"+time1+"'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
//按照民族查
public List<Message> selectByType(String type1) throws SQLException {
//插入sql 语句
String sql="select * from club where type = '"+type1+"'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
public List<Message> selectByPlace(String place1) throws SQLException {
//插入sql 语句
String sql="select * from club where place like '%"+place1+"%'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
//遍历
public List<Message> list() throws SQLException{
//插入sql语句
String sql="select * from club";
List<Message>list=new ArrayList<>();
//给集合list创造(new)一个存储空间用于存放数据
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try{
state=conn.createStatement();
rs=state.executeQuery(sql);
Message message=null;
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
//表示,把bean里的数据存入到list当中
}
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(state, conn);
}
return list;
}
//验证ID唯一
public boolean only(String name) throws SQLException {
//定义标记
boolean flag=false;
//插入sql语句
String sql="select * from volunteer where name = '"+name+"'";
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
//要用statement类的executeQuery()方法来下达select指令以查询数据库,
//executeQuery()方法会把数据库响应的查询结果存放在ResultSet类对象中供我们使用。
while (rs.next()) {
flag = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
}
Servlet.java//数据从web界面传到这里
package Service;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import DBUtil.DBUtil;
import Message.Message;
public class Service {
public boolean insert(Message message) throws SQLException{
String sql="insert into club(theme,purpose,type,time,place,object,content,arrange) values('"+message.getTheme()+"','"+message.getPurpose()+"','"+message.getType()+"','"+message.getTime()+"','"+message.getPlace()+"','"+message.getObject()+"','"+message.getContent()+"','"+message.getArrange()+"')";
Connection conn=null;//添加数据库,加载驱动
Statement state=null;//创建statement对象并置空
try {
conn=DBUtil.getConnection();
//实例化statement对象 方便操作
state=conn.createStatement();
System.out.println(sql);
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
DBUtil.close(state, conn);//close 释放资源
}
return true;
}
public boolean delete(String theme) throws SQLException{
String sql="delete from club where theme='"+theme+"' ";
Connection conn =DBUtil.getConnection();
Statement state=null;
try {
state=conn.createStatement();
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DBUtil.close(state, conn);
}
return false;
}
public boolean update(Message message) throws SQLException {
String sql="update club set purpose='"+message.getPurpose()+"',type='"+message.getType()+"',time='"+message.getTime()+"',place='"+message.getPlace()+"',object='"+message.getObject()+"',content='"+message.getContent()+"',arrange='"+message.getArrange()+"' where theme='"+message.getTheme()+"' ";
Connection conn=DBUtil.getConnection();
Statement state=null;
try {
state=conn.createStatement();
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DBUtil.close(state, conn);
}
return false;
}
public List<Message> selectByTheme(String theme1) throws SQLException {
//插入sql 语句
String sql="select * from club where theme like '%"+theme1+"%'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
//按姓名查
public List<Message> selectByTime(String time1) throws SQLException {
//插入sql 语句
String sql="select * from club where time = '"+time1+"'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
//按照民族查
public List<Message> selectByType(String type1) throws SQLException {
//插入sql 语句
String sql="select * from club where type = '"+type1+"'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
public List<Message> selectByPlace(String place1) throws SQLException {
//插入sql 语句
String sql="select * from club where place like '%"+place1+"%'";
System.out.println(sql);
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
List<Message>list=new ArrayList<>();
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
Message message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
return list;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return null;
}
//遍历
public List<Message> list() throws SQLException{
//插入sql语句
String sql="select * from club";
List<Message>list=new ArrayList<>();
//给集合list创造(new)一个存储空间用于存放数据
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try{
state=conn.createStatement();
rs=state.executeQuery(sql);
Message message=null;
while(rs.next()) {
String theme=rs.getString("theme");
String purpose=rs.getString("purpose");
String type=rs.getString("type");
String time=rs.getString("time");
String place=rs.getString("place");
String object=rs.getString("object");
String content=rs.getString("content");
String arrange=rs.getString("arrange");
message=new Message(theme,purpose,type,time,place,object,content,arrange);
list.add(message);
//表示,把bean里的数据存入到list当中
}
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(state, conn);
}
return list;
}
//验证ID唯一
public boolean only(String name) throws SQLException {
//定义标记
boolean flag=false;
//插入sql语句
String sql="select * from volunteer where name = '"+name+"'";
Connection conn=DBUtil.getConnection();
Statement state=null;
ResultSet rs=null;
try {
state=conn.createStatement();
rs=state.executeQuery(sql);
//要用statement类的executeQuery()方法来下达select指令以查询数据库,
//executeQuery()方法会把数据库响应的查询结果存放在ResultSet类对象中供我们使用。
while (rs.next()) {
flag = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
}
SelectServlet.java//查询部分传输到这
package Servlet;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Service.Service;
import Message.Message;
@WebServlet("/selectServlet")
public class SelectServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
Service service=new Service();
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//req是Request(请求)的简写,指的是从jsp/html界面请求回数据,即 jsp/html → 底层
//resp是Response(回答)的简写,指的是发送给jsp/html的数据,,即 底层 → jsp/html
req.setCharacterEncoding("utf-8");//设置从jsp或HTML中请求数据的值,也就是设置为中文,防止乱码
String way=req.getParameter("way");//getParameter()获取的是客户端设置的数据。
//
if("theme".equals(way)) {
try {
selectByTheme(req,resp);
} catch (IOException | ServletException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
else if("time".equals(way)) {
try {
selectByTime(req,resp);
} catch (IOException | ServletException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
else if("type".equals(way)) {
try {
selectByType(req,resp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
else if("place".equals(way)) {
try {
selectByPlace(req,resp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void selectByTheme(HttpServletRequest req,HttpServletResponse resp)throws IOException, ServletException, SQLException {
req.setCharacterEncoding("utf-8");
String theme=req.getParameter("mes");
List<Message> user=service.selectByTheme(theme);
req.setAttribute("user", user);
req.getRequestDispatcher("find.jsp").forward(req,resp);
//?method=list表示传一个叫做method的参数,他的值是list,你可以在Servlet中用request.getParam...获取到。
}
private void selectByTime(HttpServletRequest req,HttpServletResponse resp)throws IOException, ServletException, SQLException {
req.setCharacterEncoding("utf-8");
String time=req.getParameter("mes");
List<Message> user=service.selectByTime(time);
req.setAttribute("user", user);
req.getRequestDispatcher("find.jsp").forward(req,resp);
//?method=list表示传一个叫做method的参数,他的值是list,你可以在Servlet中用request.getParam...获取到。
}
//按照年龄
private void selectByType(HttpServletRequest req,HttpServletResponse resp)throws IOException, ServletException, SQLException {
req.setCharacterEncoding("utf-8");
String type=req.getParameter("mes");
List<Message> user=service.selectByType(type);
req.setAttribute("user", user);
req.getRequestDispatcher("find.jsp").forward(req,resp);
//?method=list表示传一个叫做method的参数,他的值是list,你可以在Servlet中用request.getParam...获取到。
}
//按照民族
private void selectByPlace(HttpServletRequest req,HttpServletResponse resp)throws IOException, ServletException, SQLException {
req.setCharacterEncoding("utf-8");
String place=req.getParameter("mes");
List<Message> user=service.selectByPlace(place);
req.setAttribute("user", user);
req.getRequestDispatcher("find.jsp").forward(req,resp);
//?method=list表示传一个叫做method的参数,他的值是list,你可以在Servlet中用request.getParam...获取到。
}
}
add.jsp//添加界面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>添加</title>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: white;
background-color: greenyellow;
}
</style>
</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: blue;">添加活动信息</h1>
<a href="login.jsp">返回主页</a>
<form action="servlet?method=insert" method="post" onsubmit="return check()">
<div class="a">
活动主题:<input type="text" id="theme" name="theme" />
</div>
<div class="a">
活动目的:<input type="text" id="purpose" name="purpose" />
</div>
<div class="a">
活动类型:
<input type="radio" id="type" name="type" checked="checked" value="社团竞赛">社团竞赛
<input type="radio" id="type" name="type" checked="checked" value="野外采风">野外采风
<input type="radio" id="type" name="type" checked="checked" value="校内集会">校内集会
<input type="radio" id="type" name="type" checked="checked" value="社团纳新">社团纳新
</div>
<div class="a">
活动时间:<input type="text" id="time" name="time" />
</div>
<div class="a">
活动地点:<input type="text" id="place" name="place" />
</div>
<div class="a">
服务类别:
<input type="checkbox" name="object" value="社团成员" οnclick="chkbox();"/>社团成员
<input type="checkbox" name="object" value="全体学生" οnclick="chkbox();"/>全体学生
</div>
<div class="a">
活动内容:<input type="text" id="content" name="content" />
</div>
<div class="a">
活动日程安排:<input type="text" id="arrange" name="arrange" />
</div>
<div class="a">
<button type="submit" class="b">添 加</button>
</div>
</form>
</div>
<script type="text/javascript">
function chkbox()
{ var obj=document.getElementsByName("matters");
var num=0;
for (var i=0;i<obj.length ;i++ )
{
if (obj[i].checked )
num+=1;
}
if (num>4)
{
alert("最多可以选择er个!");
return false;
}
}
function check()
{
var theme = document.getElementById("theme");
var purpose= document.getElementById("purpose");
var content = document.getElementById("content");
var arrange = document.getElementById("arrange");
if(theme.value.length>20)
{
alert('活动主题不超过20个汉字');
theme.focus();
return false;
}
else if(purpose.value.length>50)
{
alert('活动目的不超过50个汉字')
purpose.focus();
return false;
}
else if(content.value.length>500)
{
alert('活动内容不超过500个汉字');
content.focus();
return false;
}
else if(arrange.value.length>500)
{
alert('活动日程安排不超过500个汉字');
arrange.focus();
return false;
}
return true;
}
</script>
</body>
</html>
select.jsp//删除界面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>删除</title>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: white;
background-color: greenyellow;
}
.tb,td {
border: 1px solid black;
font-size: 22px;
}
</style>
</head>
<body>
<%
Object message = request.getAttribute("message");
Object user = request.getAttribute("user");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<h1 style="color: red;">信息列表</h1>
<a href="login.jsp">返回主页</a>
<form action="servlet?method=delete" method="post">
删除的活动主题:<input type="text" name="theme"><br>
<div class="a">
<button type="submit">删 除</button>
</div>
</form>
</div>
</body>
</html>
change.jsp//改
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>修改</title>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: white;
background-color: greenyellow;
}
</style>
</head>
<body>
<div align="center">
<h1 style="color: red;">信息修改</h1>
<a href="login.jsp">返回主页</a>
<form action="servlet?method=update" method="post" onsubmit="return check()">
<div class="a">
活动主题:<input type="text" id="theme" name="theme" />
</div>
<div class="a">
活动目的:<input type="text" id="purpose" name="purpose" />
</div>
<div class="a">
活动类型:
<input type="radio" id="type" name="type" checked="checked" value="社团竞赛">社团竞赛
<input type="radio" id="type" name="type" checked="checked" value="野外采风">野外采风
<input type="radio" id="type" name="type" checked="checked" value="校内集会">校内集会
<input type="radio" id="type" name="type" checked="checked" value="社团纳新">社团纳新
</div>
<div class="a">
活动时间:<input type="text" id="time" name="time" />
</div>
<div class="a">
活动地点:<input type="text" id="place" name="place" />
</div>
<div class="a">
服务类别:
<input type="checkbox" name="object" value="社团成员" οnclick="chkbox();"/>社团成员
<input type="checkbox" name="object" value="全体学生" οnclick="chkbox();"/>全体学生
</div>
<div class="a">
活动内容:<input type="text" id="content" name="content" />
</div>
<div class="a">
活动日程安排:<input type="text" id="arrange" name="arrange" />
</div>
<div class="a">
<button type="submit" class="b">修 改</button>
</div>
</form>
</div>
<script type="text/javascript">
function check()
{
var theme = document.getElementById("theme");
var purpose= document.getElementById("purpose");
var type=document.getElementById("type");
var time=document.getElementById("time");
var place=document.getElementById("place");
var object=document.getElementById("object");
var content = document.getElementById("content");
var arrange = document.getElementById("arrange");
if(theme.value.length>20)
{
alert('活动主题不超过20个汉字');
theme.focus();
return false;
}
else if(purpose.value.length>50)
{
alert('活动目的不超过50个汉字')
purpose.focus();
return false;
}
else if(content.value.length>500)
{
alert('活动内容不超过500个汉字');
content.focus();
return false;
}
else if(arrange.value.length>500)
{
alert('活动日程安排不超过500个汉字');
arrange.focus();
return false;
}
else if(theme.value == '')
{
alert('主题为空');
theme.focus();
return false;
}
else if(purpose.value == '')
{
alert('活动目的为空');
purpose.focus();
return false;
}
else if(type.value == '')
{
alert('活动类型为空');
type.focus();
return false;
}
else if(time.value == '')
{
alert('时间为空');
time.focus();
return false;
}
else if(place.value == '')
{
alert('地点为空');
place.focus();
return false;
}
else if(object.value == '')
{
alert('活动对象为空');
object.focus();
return false;
}
else if(content.value == '')
{
alert('活动内容为空');
content.focus();
return false;
}
else if(arrange.value == '')
{
alert('活动日程安排为空');
arrange.focus();
return false;
}
return true;
}
</script>
</body>
</html>
Find One//找
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>查询</title>
<style>
.a{
margin-top: 20px;
}
</style>
</head>
<body>
<%
Object message = request.getAttribute("message");
Object user = request.getAttribute("user");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<form action="selectServlet?" method="post" onsubmit="return check()">
<div class="a">
选择你想要查询的方式:
<select name="way" style="width:150px">
<option value="theme">按照活动主题查询</option>
<option value="time">按照活动时间查询</option>
<option value="type">按照活动类型查询</option>
<option value="place">按照活动地点查询</option>
</select>
</div>
<div class="a">
输入你要查询的信息:
<input type="text" name="mes">
</div>
<div class="a">
<button type="submit" class="b">查 询</button>
</div>
</form>
<script type="text/javascript">
function check(){
var way=document.getElmentId("way");
if(mes.value==''){
alert("输入搜索信息为空!")
mes.focus;
return false;
}
return true;
}
</script>
</body>
</html>
login.jsp//主界面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>首页</title>
<style>
.a{
font-size: 26px;
margin-top: 20px;
}
</style>
</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: blue;">校园社团活动管理系统</h1>
<div class="a">
<a href="add.jsp">发布活动信息</a>
</div>
<div class="a">
<a href="select.jsp">删除活动信息</a>
</div>
<div class="a">
<a href="change.jsp">修改活动信息</a>
</div>
<div class="a">
<a href="Find One.jsp">查询活动信息</a>
</div>
<div class="a">
<a href="servlet?method=liulan">浏览活动信息</a>
</div>
</div>
</body>
</html>
finnd.jsp//显示
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>显示</title>
<style>
.a{
margin-top: 20px;
}
.b{
font-size: 20px;
width: 160px;
color: white;
background-color: greenyellow;
}
.tb,td {
border: 1px solid black;
font-size: 22px;
}
</style>
</head>
<body>
<%
Object message = request.getAttribute("message");
Object user = request.getAttribute("user");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<h1 style="color: red;">信息列表</h1>
<a href="login.jsp">返回主页</a>
<table class="tb">
<tr>
<td>活动主题</td>
<td>活动目的</td>
<td>活动类型</td>
<td>活动时间</td>
<td>活动地点</td>
<td>活动对象</td>
<td>活动内容</td>
<td>活动日程安排</td>
</tr>
<c:forEach items="${user}" var="item">
<tr>
<td >${item.theme}</td>
<td>${item.purpose}</td>
<td>${item.type}</td>
<td>${item.time}</td>
<td>${item.place}</td>
<td>${item.object}</td>
<td>${item.content}</td>
<td>${item.arrange}</td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
需添加数据库连接包,jstl使用包
标签:String,getString,rs,期中考试,软工,state,2022,sql,message From: https://www.cnblogs.com/wjzohou/p/16837164.html