package com.crm.controller;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.UUID;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.crm.model.Info;
import com.crm.model.Infotype;
import com.crm.service.InfoService;
@Controller
@RequestMapping("/")
public class FileController {
@Resource
private InfoService InfoService;
/**
*
* @param request 从数据库中读取所有课程信息
* @param model
* @return 返回文件上传界面
*/
@RequestMapping("Upload")
public String toFileUpload(HttpServletRequest request, Model model) {
ArrayList<Infotype> list = InfoService.searchAllTypes();
model.addAttribute("list", list);
request.setAttribute("list", list);
return "fileUpload";
}
/**
*
* @param file 接收的文件
* @param request
* @param response
* @return 上传完成后重定向页面
* @throws Exception
*/
@ResponseBody
@RequestMapping("swfupload")
public String oneFileUpload2(@RequestParam("filedata") MultipartFile file, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");// 解决乱码问题
String destName; // 目标文件名
String type; // 文件类型
String address; // 文件存储路径
int size; // 文件大小
String typeid0 = request.getParameter("typeid");
String typeid1 = URLDecoder.decode(typeid0, "utf-8");
int typeid = Integer.parseInt(typeid1); // 文件所属的课程号
String infoDes0 = request.getParameter("infoDes");
String infoDes = URLDecoder.decode(infoDes0, "utf-8"); // 资料简介
String fName = file.getOriginalFilename(); // 文件源名称
size = (int) file.getSize(); // 文件大小
type = fName.substring(fName.lastIndexOf(".")); // 文件类型
destName = UUID.randomUUID() + fName; // 存储到服务器中的文件名
/*
* Boolean isUploaded = InfoService.isUpload(typeid, fName); if (isUploaded) {
* Object[] options = { "是", "否" }; JOptionPane.showOptionDialog(null,
* "该文件被上传过,是否再次上传?(不会覆盖以前上传内容)", "警告", JOptionPane.DEFAULT_OPTION,
* JOptionPane.WARNING_MESSAGE, null, options, options[0]); if
* (options.equals("2")) { return "redirect:/Upload"; } }
*/
/*
* System.out.println(typeid); System.out.println(infoDes);
* System.out.println((fName)); System.out.println(type);
* System.out.println(size); System.out.println(destName);
*/
File dir1 = new File("D:/upload/document");
File dir2 = new File("D:/upload/vedio");
File dir3 = new File("D:/upload");
if (!dir1.exists()) {
dir1.mkdirs();
}
if (!dir2.exists()) {
dir2.mkdirs();
}
// 如果是文档类型,就保存到D:/upload/document目录下
// 如果是视频类型,就保存到D:/upload/vedio目录下
// 否则,直接保存在D:/upload目录下,因为在浏览器端限制了文件上传的类型,这种情况几乎不可能发生
if (fName.endsWith(".doc") || fName.endsWith(".docx") || fName.endsWith(".ppt") || fName.endsWith(".pptx")
|| fName.endsWith(".pdf")) {
File f = new File(dir1, destName);
address = f.getAbsolutePath();
file.transferTo(f);
} else if (fName.endsWith(".mp4") || fName.endsWith(".avi") || fName.endsWith(".mpeg") || fName.endsWith(".mov")
|| fName.endsWith(".wmv") || fName.endsWith(".qlv") || fName.endsWith(".flv") || fName.endsWith(".3gp")
|| fName.endsWith(".rm")) {
File f = new File(dir2, destName);
address = f.getAbsolutePath();
file.transferTo(f);
} else {
File f = new File(dir3, destName);
address = f.getAbsolutePath();
file.transferTo(f);
}
// 将上传文件的相关信息保存到数据库
Info info = new Info(fName, address, infoDes, size, type, typeid);
InfoService.insertInfo(info);
return "redirect:/Upload";
}
// 后台管理页面
@RequestMapping("listInManager")
public String toManager(HttpServletRequest request, Model model) {
ArrayList<Info> list = InfoService.searchAllInfos();
for (int i = 0; i < list.size(); i++) {
list.get(i).setInfotype((InfoService.getTypeById(list.get(i).getTypeid())));
}
model.addAttribute("list", list);
request.setAttribute("list", list);
return "manager";
}
/*
* 获取当前页码
*/
private int getPageCode(HttpServletRequest req) {
String pageCode = req.getParameter("pc");
if (pageCode == null)
return 1;
try {
return Integer.parseInt(pageCode);
} catch (RuntimeException e) {
return 1;
}
}
/*
* 获取请求的url,但去除pc参数
*/
private String getUrl(HttpServletRequest req) {
String url = req.getRequestURI() + "?" + req.getQueryString();
int fromIndex = url.lastIndexOf("&pc=");
if (fromIndex == -1)
return url;
int toIndex = url.indexOf("&", fromIndex + 1);
if (toIndex == -1)
return url.substring(0, fromIndex);
return url.substring(0, fromIndex) + url.substring(toIndex);
}
/*
* 管理页面 分页列出所有资料信息
*/
/*
* @RequestMapping("listInManager") public String toManager(HttpServletRequest
* request, Model model) { ArrayList<Info> list = InfoService.searchAllInfos();
*
* 1. 获取当前页码
*
* int pc = getPageCode(request);
*
* 2. 使用InfoService查询,得到PageBean
*
* Page<Info> pb = InfoService.searchInfosByPc(pc);
*
* 3. 获取url,设置给PageBean
*
* String url = getUrl(request); pb.setUrl(url);
*
* 4. 把Page保存到request,转发到/jsps/book/list.jsp
*
* request.setAttribute("pb", pb);
*
* model.addAttribute("list", list); request.setAttribute("list", list); return
* "manager"; }
*/
// 通过资料名查找资料
@RequestMapping("selectByName")
public String toSelectByName(@Param("name") String name, HttpServletRequest request, Model model) {
ArrayList<Info> list = InfoService.searchByKeyWord(name);
for (int i = 0; i < list.size(); i++) {
list.get(i).setInfotype((InfoService.getTypeById(list.get(i).getTypeid())));
}
model.addAttribute("list", list);
request.setAttribute("list", list);
return "manager";
}
// 通过id查找编辑资料
@RequestMapping("editById")
public String toEditById(@Param("id") int id, HttpServletRequest request, Model model) {
ArrayList<Infotype> list = InfoService.searchAllTypes();
model.addAttribute("list", list);
request.setAttribute("list", list);
Info info = InfoService.getInfoById(id);
info.setInfotype(InfoService.getTypeById(info.getTypeid()));
model.addAttribute("info", info);
request.setAttribute("info", info);
InfoService.updateById(info);
return "edit";
}
/*
* 根据typeid查询所有该课程内的资料
*/
@RequestMapping("searchInfosByTypeid")
public String toSearchSubjcet(@Param("typeid") Integer typeid, HttpServletRequest request, Model model) {
ArrayList<Info> list = InfoService.searchInfosByTypeid(typeid);
for (int i = 0; i < list.size(); i++) {
list.get(i).setInfotype((InfoService.getTypeById(list.get(i).getTypeid())));
}
model.addAttribute("list", list);
request.setAttribute("list", list);
return "manager";
}
/*
* 修改成功返回管理页面
*/
@RequestMapping("update")
public String toUpdate(@Param("id") Integer id, @Param("address") String address
没有合适的资源?快使用搜索试试~ 我知道了~
SpringMVC框架下使用swfuploader控件进行多文件同时上传
共72个文件
xml:12个
jar:10个
java:7个
需积分: 12 13 下载量 21 浏览量
2017-09-26
14:15:03
上传
评论
收藏 4.33MB RAR 举报
温馨提示
在SpringMvc框架下,通过swfuploader控件实现多文件同时上传到服务器,并且可对文件的类型,大小进行限制,以及将文件的相关描述信息等写入数据库(这里使用的是SQL Server),并实现了简单的对数据库的更新操作。
资源推荐
资源详情
资源评论
收起资源包目录
ssm.rar (72个子文件)
ssm
pom.xml 6KB
target
test-classes
m2e-wtp
web-resources
META-INF
maven
com.scut.sf
mypoem
pom.xml 6KB
pom.properties 216B
MANIFEST.MF 123B
classes
database.properties 231B
springmvc.xml 3KB
spring-mybatis.xml 3KB
log4j.properties 4KB
com
crm
dao
InfoDao.class 1002B
model
Infotype.class 893B
Page.class 2KB
Info.class 3KB
mapping
Infotype.xml 677B
Info.xml 3KB
controller
FileController.class 9KB
service
InfoService.class 925B
impl
InfoServiceImpl.class 3KB
.settings
org.eclipse.m2e.core.prefs 86B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.core.resources.prefs 104B
org.eclipse.wst.common.component 732B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.validation.prefs 48B
.jsdtscope 626B
org.eclipse.jdt.core.prefs 723B
src
test
java
main
webapp
images
selectfile.png 29KB
cancelbutton.gif 1KB
Css
stream-v1.css 3KB
swfupload
default.css 6KB
pager.css 1KB
bootstrap.css 124KB
bootstrap-responsive.css 22KB
style.css 2KB
WEB-INF
web.xml 2KB
views
pager.jsp 3KB
manager.jsp 3KB
infoDetail.jsp 3KB
fileUpload.jsp 3KB
edit.jsp 3KB
lib
javassist-3.11.0.GA.jar 600KB
struts2-core-2.3.20.jar 807KB
freemarker-2.3.19.jar 909KB
struts2-json-plugin-2.3.20.jar 70KB
xwork-core-2.3.20.jar 656KB
ognl-3.0.6.jar 223KB
commons-io-2.2.jar 170KB
commons-lang3-3.2.jar 376KB
commons-fileupload-1.3.1.jar 67KB
Js
swfupload
swfupload.js 38KB
swfupload.swf 12KB
handlers.js 9KB
swfupload.queue.js 3KB
fileprogress.js 7KB
filecheck.js 2KB
swfup.js 4KB
resources
database.properties 231B
springmvc.xml 3KB
spring-mybatis.xml 3KB
log4j.properties 4KB
java
com
crm
dao
InfoDao.java 754B
model
Infotype.java 724B
Info.java 2KB
Page.java 1KB
mapping
Infotype.xml 677B
Info.xml 3KB
controller
FileController.java 9KB
service
InfoService.java 1KB
impl
InfoServiceImpl.java 2KB
.project 1KB
.classpath 2KB
sqljdbc41.jar 872KB
共 72 条
- 1
资源评论
qq_36463628
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功