基于javaweb+mysql的jsp+servlet高校社团管理系统(java+servlet+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet高校社团管理系统(java+servlet+jsp+mysql)
功能简介
高校社团管理系统分为前后台,角色分为三种:管理员、社长、普通社员。
超级管理员角色包含以下功能:会员管理,物品管理,活动审批,系统用户管理,社团添加删除等功能。
社长角色包含以下功能:社团管理员登录,会员管理,物品管理,活动管理,查询社团信息,密码修改等功能。
普通社员角色包含以下功能:社员登录,申请入社,物品查看,活动申请等功能。
前台主要是展示社团列表、社团风采、社团活动、新闻列表 前台登录后进入个人中心,在个人中心能申请加入社团、查看参加的社团活动等 后台为管理员与社长使用,应用于对社团的管理及内容发布等。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 8.0版本;
使用技术 使用技术:servlet+jsp+mysql 8.0
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;注:数据库使用mysql 8.0,注意版本要匹配,否则可能会产生连接异常的情况, 2. 将项目中db.properties配置文件中的数据库配置改为自己的配置 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
前台地址:http://localhost:8080/team/front/login.jsp 普通社员账号:苏c 密码:123
后台地址:http://localhost:8080/team/mui/login.jsp 管理员账号:sys 密码:123456 社长账号:苏悲 密码:123456
page = roleService.page(role, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/roleList.jsp").forward(request, response);
}
//form跳转页面
private void form(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
Role role = new Role();
if (id!=null && id!="") {
role = roleService.getById(id);
}
request.setAttribute("role", role);
request.getRequestDispatcher("/views/system/roleForm.jsp").forward(request, response);
}
}
/**
* Servlet implementation class DownloadController
*/
@WebServlet(name = "download", urlPatterns = { "/download" })
public class DownloadController extends HttpServlet {
private static final long serialVersionUID = 1L;
// 字符编码
private final String ENCODING = "GB2312";
// 内容类型
private final String CONTENT_TYPE = "text/html;charset=gb2312";
// 要下载的文件存放的路径
private String downloadfiledir = "d:\\temp\\";
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String applayTeam = request.getParameter("applayTeam");
if (applayTeam != null && applayTeam != "") {
teamApplay.setApplayTeam(applayTeam);
request.setAttribute("applayTeam", applayTeam);
}
String applayStu = request.getParameter("applayStu");
if (applayStu != null && applayStu != "") {
teamApplay.setApplayStu(applayStu);
request.setAttribute("applayStu", applayStu);
}
String applayType = request.getParameter("applayType");
if (applayType != null && applayType != "") {
teamApplay.setApplayType(applayType);
request.setAttribute("applayType", applayType);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
//根据登录用户查出所有的社团
User currentUser = CurrentUserUtils.getCurrentUser(request);
String roleFlag = currentUser.getRole2().getRoleFlag();
if ("leader".equals(roleFlag)) {
//如果是社长,查出自己负责的所以社团
Teams teams = new Teams();
teams.setBuildStu(currentUser.getId());
List<Teams> findAll = teamsService.findAll(teams);
request.setAttribute("teamList", findAll);
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(" and a.applay_team in (");
for (Teams teams2 : findAll) {
stringBuffer.append("'"+teams2.getId()+"',");
}
stringBuffer.append(" '1')");
teamApplay.setSqlStr(stringBuffer.toString());
}else{
request.setAttribute("teamList", teamsService.findAll(new Teams()));
String remark = request.getParameter("remark");
Teams teams = new Teams();
teams.setId(id);
teams.setTeamName(teamName);
teams.setPic(pic);
teams.setTeamIntro(teamIntro);
teams.setBuildStu(buildStu);
teams.setAuditType(auditType);
teams.setMembers(Integer.parseInt(members));
teams.setRemark(remark);
teamsService.update(teams);
request.setAttribute("teams", teams);
request.getRequestDispatcher("/views/team/teamsForm.jsp").forward(request, response);
}
//列表查询
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
Teams teams = new Teams();
//分页有关
Page<Teams> page = new Page<Teams>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String teamName = request.getParameter("teamName");
if (teamName != null && teamName != "") {
teams.setTeamName(teamName);
request.setAttribute("teamName", teamName);
}
String buildStu = request.getParameter("buildStu");
if (buildStu != null && buildStu != "") {
teams.setBuildStu(buildStu);
request.setAttribute("buildStu", buildStu);
}
String auditType = request.getParameter("auditType");
if (auditType != null && auditType != "") {
teams.setAuditType(auditType);
request.setAttribute("auditType", auditType);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page = teamsService.page(teams, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/team/teamsList.jsp").forward(request, response);
}
//上传到服务器硬盘上,保证重启tomcat不会丢失文件
//获取上传文件的路径
// String savePath = PropertiesUtil.getValue("fileUpload");
// File file = new File(savePath+"/");
// if (!file.exists() && !file.isDirectory()) {
// System.out.println(savePath+"目录不存在,需要创建");
// //创建目录
// file.mkdirs();
// }
//消息提示
String msg = "";
try{
//使用Apache文件上传组件处理文件上传步骤:
//1、创建一个DiskFileItemFactory工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
//解决上传文件名的中文乱码
upload.setHeaderEncoding("UTF-8");
//3、判断提交上来的数据是否是上传表单的数据
if(!ServletFileUpload.isMultipartContent(request)){
//按照传统方式获取数据
return;
}
//4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
List<FileItem> list = upload.parseRequest(request);
for(FileItem item : list){
//如果fileitem中封装的是普通输入项的数据
if(item.isFormField()){
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
if ("id".endsWith(name)) {
if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
teamApplay.setId(item.getString("UTF-8"));
}
}
if ("applayTeam".endsWith(name)) {
teamApplay.setApplayTeam(item.getString("UTF-8"));
}
if ("applayStu".endsWith(name)) {
teamApplay.setApplayStu(item.getString("UTF-8"));
}
if ("applayContent".endsWith(name)) {
teamApplay.setApplayContent(item.getString("UTF-8"));
private static final long serialVersionUID = 1L;
private String contextPath = "";
MoneyMangerDao moneyMangerDao=new MoneyMangerDao();
MoneyMangerService moneyMangerService = new MoneyMangerServiceImpl();
SiteNewsService siteNewsService = new SiteNewsServiceImpl();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
contextPath = request.getServletContext().getContextPath();
String method = request.getParameter("method");
if ("save".equals(method)) {
save(request,response);
}else if ("delete".equals(method)) {
delete(request, response);
}else if ("list".equals(method)) {
list(request, response);
}else if ("form".equals(method)) {
form(request, response);
}
}
//添加保存
protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MoneyManger moneyManger = new MoneyManger();
//这是上传到tomcat下,文件容易丢失
//得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String savePath = this.getServletContext().getRealPath("/upload");
File file = new File(savePath);
//判断上传文件的保存目录是否存在
if (!file.exists() && !file.isDirectory()) {
System.out.println(savePath+"目录不存在,需要创建");
//创建目录
file.mkdir();
}
//上传到服务器硬盘上,保证重启tomcat不会丢失文件
//获取上传文件的路径
// String savePath = PropertiesUtil.getValue("fileBaseUrl")+ PropertiesUtil.getValue("fileUrl");
// File file = new File(savePath+"/");
// if (!file.exists() && !file.isDirectory()) {
// System.out.println(savePath+"目录不存在,需要创建");
// //创建目录
// file.mkdirs();
}
}
if ("roleName".endsWith(name)) {
role.setRoleName(item.getString("UTF-8"));
}
if ("roleFlag".endsWith(name)) {
role.setRoleFlag(item.getString("UTF-8"));
}
if ("introduce".endsWith(name)) {
role.setIntroduce(item.getString("UTF-8"));
}
}else{//如果fileitem中封装的是上传文件
//得到上传的文件名称,
String filename = item.getName();
System.out.println(filename);
if(filename==null || filename.trim().equals("")){
continue;
}
//注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
//处理获取到的上传文件的文件名的路径部分,只保留文件名部分
filename = filename.substring(filename.lastIndexOf("\\")+1);
//获取item中的上传文件的输入流
InputStream in = item.getInputStream();
//创建一个文件输出流
FileOutputStream out = new FileOutputStream(savePath + "\\" + filename);
//创建一个缓冲区
byte buffer[] = new byte[1024];
//判断输入流中的数据是否已经读完的标识
int len = 0;
//循环将输入流读入到缓冲区当中,(len=in.read(buffer))>0就表示in里面还有数据
while((len=in.read(buffer))>0){
//使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
out.write(buffer, 0, len);
}
//关闭输入流
in.close();
//关闭输出流
out.close();
//删除处理文件上传时生成的临时文件
item.delete();
msg = "文件上传成功!";
//1、创建一个DiskFileItemFactory工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
//解决上传文件名的中文乱码
upload.setHeaderEncoding("UTF-8");
//3、判断提交上来的数据是否是上传表单的数据
if(!ServletFileUpload.isMultipartContent(request)){
//按照传统方式获取数据
return;
}
//4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
List<FileItem> list = upload.parseRequest(request);
for(FileItem item : list){
//如果fileitem中封装的是普通输入项的数据
if(item.isFormField()){
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
if ("id".endsWith(name)) {
if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
teams.setId(item.getString("UTF-8"));
}
}
if ("teamName".endsWith(name)) {
teams.setTeamName(item.getString("UTF-8"));
}
if ("pic".endsWith(name)) {
teams.setPic(item.getString("UTF-8"));
}
if ("teamIntro".endsWith(name)) {
teams.setTeamIntro(item.getString("UTF-8"));
}
if ("buildTime".endsWith(name)) {
teams.setBuildTime(Timestamp.valueOf(item.getString("UTF-8")));
}
if ("buildStu".endsWith(name)) {
teams.setBuildStu(item.getString("UTF-8"));
}
teamApplay.setApplayContent(applayContent);
teamApplay.setApplayType(applayType);
teamApplayService.add(teamApplay);
response.sendRedirect(contextPath+"/teamApplay?method=list");
}
//添加保存
protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
TeamApplay teamApplay = new TeamApplay();
//这是上传到tomcat下,文件容易丢失
//得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String savePath = this.getServletContext().getRealPath("/upload");
File file = new File(savePath);
//判断上传文件的保存目录是否存在
if (!file.exists() && !file.isDirectory()) {
System.out.println(savePath+"目录不存在,需要创建");
//创建目录
file.mkdir();
}
//上传到服务器硬盘上,保证重启tomcat不会丢失文件
//获取上传文件的路径
// String savePath = PropertiesUtil.getValue("fileUpload");
// File file = new File(savePath+"/");
// if (!file.exists() && !file.isDirectory()) {
// System.out.println(savePath+"目录不存在,需要创建");
// //创建目录
// file.mkdirs();
// }
//消息提示
String msg = "";
try{
//使用Apache文件上传组件处理文件上传步骤:
//1、创建一个DiskFileItemFactory工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
//解决上传文件名的中文乱码
upload.setHeaderEncoding("UTF-8");
//3、判断提交上来的数据是否是上传表单的数据
if(!ServletFileUpload.isMultipartContent(request)){
//按照传统方式获取数据
return;
}
//4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
List<FileItem> list = upload.parseRequest(request);
for(FileItem item : list){
//如果fileitem中封装的是普通输入项的数据
if(item.isFormField()){
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
if ("id".endsWith(name)) {
if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
teamApplay.setId(item.getString("UTF-8"));
}
//这是上传到tomcat下,文件容易丢失
//得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String savePath = this.getServletContext().getRealPath("/upload");
File file = new File(savePath);
//判断上传文件的保存目录是否存在
if (!file.exists() && !file.isDirectory()) {
System.out.println(savePath+"目录不存在,需要创建");
//创建目录
file.mkdir();
}
//上传到服务器硬盘上,保证重启tomcat不会丢失文件
//获取上传文件的路径
// String savePath = PropertiesUtil.getValue("fileUpload");
// File file = new File(savePath+"/");
// if (!file.exists() && !file.isDirectory()) {
// System.out.println(savePath+"目录不存在,需要创建");
// //创建目录
// file.mkdirs();
// }
//消息提示
String msg = "";
try{
//使用Apache文件上传组件处理文件上传步骤:
//1、创建一个DiskFileItemFactory工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
//解决上传文件名的中文乱码
upload.setHeaderEncoding("UTF-8");
//3、判断提交上来的数据是否是上传表单的数据
if(!ServletFileUpload.isMultipartContent(request)){
//按照传统方式获取数据
return;
}
//4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
List<FileItem> list = upload.parseRequest(request);
for(FileItem item : list){
//如果fileitem中封装的是普通输入项的数据
if(item.isFormField()){
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
// 设置response对象的ContentType
response.setContentType(CONTENT_TYPE);
// 输出错误信息
PrintWriter out = response.getWriter();
out.println("<font color=red>输入的文件名无效!</font>");
out.close();
} else {
// 下载文件的完整路径名
String fullfilename = realPath + filename;
System.out.println("下载文件:" + fullfilename);
// 根据文件的类型设置response对象的ContentType
String contentType = getServletContext().getMimeType(fullfilename);
if (contentType == null)
contentType = "application/octet-stream";
response.setContentType(contentType);
// 设置response的头信息
response.setHeader("Content-disposition", "attachment;filename=\"" + filename + "\"");
InputStream is = null;
OutputStream os = null;
try {
activeStuService.delete(id);
response.sendRedirect(contextPath+"/activeStu?method=list");
}
//修改
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String activeId = request.getParameter("activeId");
String stuId = request.getParameter("stuId");
String stuName = request.getParameter("stuName");
String phone = request.getParameter("phone");
String type = request.getParameter("type");
String isArrive = request.getParameter("isArrive");
ActiveStu activeStu = new ActiveStu();
activeStu.setId(id);
activeStu.setActiveId(activeId);
activeStu.setStuId(stuId);
activeStu.setStuName(stuName);
activeStu.setPhone(phone);
activeStu.setType(type);
activeStu.setIsArrive(isArrive);
activeStuService.update(activeStu);
request.setAttribute("activeStu", activeStu);
request.getRequestDispatcher("/views/team/activeStuForm.jsp").forward(request, response);
}
//列表查询
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
ActiveStu activeStu = new ActiveStu();
//分页有关
Page<ActiveStu> page = new Page<ActiveStu>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String activeId = request.getParameter("activeId");
if (activeId != null && activeId != "") {
activeStu.setActiveId(activeId);
request.setAttribute("activeId", activeId);
}
String stuId = request.getParameter("stuId");
if (stuId != null && stuId != "") {
activeStu.setStuId(stuId);
request.setAttribute("stuId", stuId);
}
String stuName = request.getParameter("stuName");
if (stuName != null && stuName != "") {
activeStu.setStuName(stuName);
request.setAttribute("stuName", stuName);
}
student.setPhone(item.getString("UTF-8"));
}
if ("pic".endsWith(name)) {
student.setPic(item.getString("UTF-8"));
}
if ("remark".endsWith(name)) {
student.setRemark(item.getString("UTF-8"));
}
}else{//如果fileitem中封装的是上传文件
//得到上传的文件名称,
String filename = item.getName();
System.out.println(filename);
if(filename==null || filename.trim().equals("")){
continue;
}
//注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
//处理获取到的上传文件的文件名的路径部分,只保留文件名部分
filename = filename.substring(filename.lastIndexOf("\\")+1);
//获取item中的上传文件的输入流
InputStream in = item.getInputStream();
//创建一个文件输出流
FileOutputStream out = new FileOutputStream(savePath + "\\" + filename);
//创建一个缓冲区
byte buffer[] = new byte[1024];
//判断输入流中的数据是否已经读完的标识
int len = 0;
//循环将输入流读入到缓冲区当中,(len=in.read(buffer))>0就表示in里面还有数据
while((len=in.read(buffer))>0){
//使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
out.write(buffer, 0, len);
}
//关闭输入流
in.close();
//关闭输出流
out.close();
//删除处理文件上传时生成的临时文件
item.delete();
msg = "文件上传成功!";
boolean nextUpperCase = true;
if (i < (s.length() - 1)) {
nextUpperCase = Character.isUpperCase(s.charAt(i + 1));
}
if ((i > 0) && Character.isUpperCase(c)) {
if (!upperCase || !nextUpperCase) {
sb.append(SEPARATOR);
}
upperCase = true;
} else {
upperCase = false;
}
sb.append(Character.toLowerCase(c));
}
return sb.toString();
}
}
/**
* 这是过滤器,用于设置请求与响应的字符集编码
* @ClassName: SerFilter
* @Description: TODO(这里用一句话描述这个类的作用)
*/
@WebFilter("/*")
public class SerFilter implements Filter {
//循环将输入流读入到缓冲区当中,(len=in.read(buffer))>0就表示in里面还有数据
while((len=in.read(buffer))>0){
//使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
out.write(buffer, 0, len);
}
//关闭输入流
in.close();
//关闭输出流
out.close();
//删除处理文件上传时生成的临时文件
item.delete();
msg = "文件上传成功!";
siteNews.setPic(request.getContextPath()+"/upload" + "/" + filename);
}
}
if (siteNews.getId()!=null && !"".equals(siteNews.getId())) {
siteNewsService.update(siteNews);
}else{
String username = CurrentUserUtils.getCurrentUser(request).getUsername();
siteNews.setCreateUser(username);
siteNewsService.add(siteNews);
}
response.sendRedirect(contextPath+"/siteNews?method=list&newsType="+siteNews.getNewsType());
}catch (Exception e) {
msg= "文件上传失败!";
e.printStackTrace();
request.setAttribute("msg",msg);
request.getRequestDispatcher("/views/team/siteNewsForm.jsp").forward(request, response);
}
}
//删除
private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String newsType = siteNewsService.getById(id).getNewsType();
siteNewsService.delete(id);
response.sendRedirect(contextPath+"/siteNews?method=list&newsType="+newsType);
}
//修改
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String newsType = request.getParameter("newsType");
String title = request.getParameter("title");
String pic = request.getParameter("pic");
String shortContent = request.getParameter("shortContent");
String content = request.getParameter("content");
String createUser = request.getParameter("createUser");
String createTime = request.getParameter("createTime");
String isRun = request.getParameter("isRun");
String belonTeam = request.getParameter("belonTeam");
String isAudit = request.getParameter("isAudit");
response.setHeader("Content-disposition", "attachment;filename=\"" + filename + "\"");
InputStream is = null;
OutputStream os = null;
try {
is = new BufferedInputStream(new FileInputStream(fullfilename));
// 定义输出字节流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// 定义response的输出流
os = new BufferedOutputStream(response.getOutputStream());
// 定义buffer
byte[] buffer = new byte[4 * 1024]; // 4k Buffer
int read = 0;
// 从文件中读入数据并写到输出字节流中
while ((read = is.read(buffer)) != -1) {
baos.write(buffer, 0, read);
}
// 将输出字节流写到response的输出流中
os.write(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭输出字节流和response输出流
os.close();
is.close();
}
}
}
}
//使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
out.write(buffer, 0, len);
}
//关闭输入流
in.close();
//关闭输出流
out.close();
//删除处理文件上传时生成的临时文件
item.delete();
msg = "文件上传成功!";
}
}
if (teamApplay.getId()!=null && !"".equals(teamApplay.getId())) {
teamApplayService.update(teamApplay);
}else{
teamApplayService.add(teamApplay);
}
response.sendRedirect(contextPath+"/teamApplay?method=list");
}catch (Exception e) {
msg= "文件上传失败!";
e.printStackTrace();
request.setAttribute("msg",msg);
request.getRequestDispatcher("/views/team/teamApplayForm.jsp").forward(request, response);
}
}
//删除
private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
teamApplayService.delete(id);
response.sendRedirect(contextPath+"/teamApplay?method=list");
}
//修改
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String applayTeam = request.getParameter("applayTeam");
String applayStu = request.getParameter("applayStu");
String applayContent = request.getParameter("applayContent");
String applayTime = request.getParameter("applayTime");
@WebServlet("/teams")
public class TeamsController extends HttpServlet {
private static final long serialVersionUID = 1L;
private String contextPath = "";
TeamsDao teamsDao=new TeamsDao();
TeamsService teamsService = new TeamsServiceImpl();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
contextPath = request.getServletContext().getContextPath();
String method = request.getParameter("method");
if ("add".equals(method)) {
add(request,response);
}else if ("delete".equals(method)) {
delete(request, response);
}else if ("list".equals(method)) {
list(request, response);
}else if ("update".equals(method)) {
update(request, response);
}else if ("form".equals(method)) {
form(request, response);
}else if ("save".equals(method)) {
save(request, response);
}else if ("count".equals(method)) {
count(request, response);
}
}
private void count(HttpServletRequest request, HttpServletResponse response) {
}