基于javaweb+mysql的ssm技术论坛bbs系统(java+ssm+jsp+bootstrap+mysql)

基于javaweb+mysql的ssm技术论坛bbs系统(java+ssm+jsp+bootstrap+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SSM技术论坛bbs系统(java+ssm+jsp+bootstrap+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.数据库:MySql 5.7版本; 6.是否Maven项目: 否;

技术栈

  1. 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+bootstrap+jQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中beans.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
				Ztree ztree=new Ztree();
				ztree.setId(bankuai.getId());
				ztree.setpId(bankuai.getParentId());
				ztree.setName(bankuai.getName());
				if(bankuai.getId()==pbankuaiid){
					ztree.setOpen(true);
				}else{
					ztree.setOpen(false);
				}
				ztree.setNocheck(true);
				list.add(ztree);
			}
		}
		System.out.println(new Gson().toJson(list));
		model.addAttribute("zNodes", new Gson().toJson(list));
		model.addAttribute("tieziid", id);
		return "jsp/index/user/ztreeyidong";
	}
	
	//移动板块根据主题移动
	@ResponseBody
	@RequestMapping("updatebankuai.do")
	public Map<String, String> updatebankuai(HttpServletRequest request,int tieziid,int zhutiid) {
		zhutiid=zhutiid-10000;
		Map<String, String> map=new HashMap<String, String>();
		User user=(User) request.getSession().getAttribute(PublicStatic.USER);
		
		//查询帖子所在板块
		Tiezi tiezisql=new Tiezi();
		tiezisql.setId(tieziid);
		tiezisql = tieziService.findbytieziwhere(tiezisql);
		
		//查询主题的板块名称和id
		Zhuti zhuti=new Zhuti();
		zhuti.setId(zhutiid);
		zhuti = zhutiService.findbyid(zhuti);
		//更新帖子
		Tiezi tiezi=new Tiezi();
		tiezi.setBankuaiId(zhuti.getBankuaiId());
		tiezi.setZhutiid(zhuti.getId()+"");
		tiezi.setId(tieziid);
		tiezi.setLastupdate(""+user.getGroupname()+"\""+user.getLoginname()+"\"于"+Tool.getyyyyMMddHHmmss()+"将帖子从“"+tiezisql.getBankuainame()+"”板块“"+tiezisql.getZhutiname()+"”主题移动到“"+zhuti.getBankuainame()+"”板块“"+zhuti.getName()+"”主题"+"</br>");
		}
		//更新帖子信息,并记录操作日志
		Tiezi tieziupdate =new Tiezi();
		tieziupdate.setId(tiezi.getId());
		tieziupdate.setZhutiid(tiezi.getZhutiid());
		tieziupdate.setName(tiezi.getName());
		tieziupdate.setContenthtml(tiezi.getContenthtml());
		tieziupdate.setContenttxt(tiezi.getContenttxt());
		tieziupdate.setLastupdate("您的帖子在"+Tool.getyyyyMMddHHmmss()+"被"+sessionuser.getLoginname()+"编辑<br/>");
		tieziupdate.setName(Tool.replacezhuanyi(tiezi.getName()));
		tieziupdate.setContenthtml(Tool.replacezhuanyi(tiezi.getContenthtml()));
		tieziService.update(tieziupdate);
		return "redirect:/bk/index.do?bankuaiid="+tiezi.getBankuaiId();
	}
	
	
	//保存回复信息
	@ResponseBody
	@RequestMapping("addhuifu.do")
	public String addhuifu(HttpServletRequest request,HttpServletResponse response, Model model,int id,String editortxt,String editorhtml,Integer huifuid) {
		if(Tool.isstopip(request, response, 5)){
			return null;
		}
		User sessionuser=(User)request.getSession().getAttribute(PublicStatic.USER);
		Map<String, Object> map= tieziService.findbytieziid(id+"");
		//验证是否有回复权限
		String flag = userService.ishuifu(map.get("huifugroup")+"", sessionuser);
		if(!flag.equals("1")){
			return flag;
		}
		Huifu huifu=new Huifu();
		huifu.setContenthtml(editorhtml);
		huifu.setContenttxt(editortxt);
		huifu.setCreateuserid(sessionuser.getId());
		huifu.setTieziid(id);
		huifu.setCreatetime(Tool.getyyyyMMddHHmmss());
		huifu.setIsdel("0");
		huifu.setHuifuid(huifuid);
		huifu.setOrderby(huifuService.maxobderby(id));
		huifuService.insert(huifu);
	}
	
    //获取文件名
    private String getfilenamelast(String filename){
    	int start=filename.lastIndexOf(".");
    	if(start!=-1){
    		filename=filename.substring(start, filename.length());
    	}
    	return filename;
    }
    
}

/*
 * 展示图片
 * 
 */

@Controller
@RequestMapping("/download")
public class DownloadController {

	//展示图片
	@RequestMapping("downloadimg.do")
	public void downloadimg(HttpServletRequest request,String f, HttpServletResponse response) {
		try {
			if("".equals(f))f="touxiang.jpg";
			FileInputStream is = new FileInputStream(PublicStatic.FILE_PATH+"image/"+f);
			int i = is.available(); // 得到文件大小  
			byte data[] = new byte[i];
			is.read(data); // 读数据  
			is.close();

/*
 * 登陆
 * 
 */
@Controller
@RequestMapping("/login")
public class LoginController {

	@Autowired
	UserService userService;
	
	@Autowired
	JifenService jifenService;
	
	
	private static Logger log = Logger.getLogger(LoginController.class);
	
	//修改或者新增
	@RequestMapping("index.do")
	public String toindex(HttpServletRequest request,HttpServletResponse response,Model model,String pathlocation) {
		if(Tool.isstopip(request, response, 3)){
			return null;
		}
		model.addAttribute("pathlocation", pathlocation);
		Cookie[] cookies = request.getCookies();
		for(Cookie cookie : cookies){
		    String name=cookie.getName();
		    if("javaeelogin".equals(name)){
		    	String value=cookie.getValue();
		    	User user=new User();
		    	user.setCookieid(value);
		    	List<User> list = userService.find(user);
		    	if(list.size()>0){
		    		User usersession=list.get(0);
		    		request.getSession().setAttribute(PublicStatic.USER, usersession);
		    		Jifen jifen=new Jifen();
					jifen.setFenshu(PublicStatic.JIFEN_LOGIN);
					jifen.setUserid(usersession.getId());
					jifen.setType("104");
					jifen.setContent("每天第一次登录您获得"+PublicStatic.JIFEN_LOGIN+"积分");
					int findnowcount = jifenService.findnowcount(jifen);
					if(findnowcount==0){
						jifenService.insert(jifen);
					}
					Cookie c = new Cookie("login",usersession.getCookieid());
					c.setMaxAge(60*60*24*14);
					c.setPath("/");
					response.addCookie(c);
	@RequestMapping("del.do")
	public String del(int id) {
		String result=bankuaiService.delete(id);
		return result;
	}
	
	//删除
	@ResponseBody
	@RequestMapping("getpinyin.do")
	public String getpinyin(String name) {
		String getpinyin = Pinyin4j.getpinyin(name);
		Bankuai bankuai=new Bankuai();
		bankuai.setYuming(getpinyin);
		List<Bankuai> list = bankuaiService.select(bankuai);
		if(list.size()>0){
			getpinyin=getpinyin+Tool.getRandom();
		}
		return getpinyin;
	}
	
	
	
}

		jifen.setUserid(sessionuser.getId());
		jifen.setType("101");
		jifen.setContent("您发布了帖子获得"+PublicStatic.JIFEN_FATIE+"积分");
		int findnowcount = jifenService.findnowcount(jifen);
		//如果发帖次数小于等于这个时间,增加积分
		if(findnowcount<=PublicStatic.JIFEN_FATIE_COUNT){
			jifenService.insert(jifen);
		}
		
		//启动缓存线程
		new IndexThread().start();
		return "redirect:/"+tiezi.getYuming()+"/";
	}
	
	//跳转编辑发帖页面
	@RequestMapping("toupdate.do")
	public String toupdate(HttpServletRequest request,HttpServletResponse response, Model model,PageBean<Tiezi> page,String tieziid) {
		if(Tool.isstopip(request, response, 4)){
			return null;
		}
		Tiezi tiezi=new Tiezi();
		tiezi.setId(Integer.parseInt(tieziid));
		tiezi = tieziService.findbytieziwhere(tiezi);
		String id=tiezi.getBankuaiId()+"";
		Bankuai bankuai= bankuaiService.findbyid(id);
		User user=(User)request.getSession().getAttribute(PublicStatic.USER);
		boolean flag=userService.isfatie(bankuai.getFatiegroup(),user);
		//判断是否有编辑权限
		if(Tool.isguanliyuan(user)){
			if(!flag){
				return "redirect:/topage/quanxian.do";
			}
		}
		Zhuti zhuti=new Zhuti();
		zhuti.setBankuaiId(Integer.parseInt(id));
		List<Zhuti> zhutilist = zhutiService.find(zhuti);
		page = tieziService.findpagebybankuanid(tiezi, page);
		//今日的帖子总数
		int nowcount=tieziService.findnowcount(id);
		model.addAttribute("zhutilist", zhutilist);
		model.addAttribute("bankuaiId", id);
		model.addAttribute("bankuai", bankuai);
		model.addAttribute("page", page);
		model.addAttribute("nowcount", nowcount);
		model.addAttribute("tiezi", tiezi);
		return "jsp/index/user/updatefatie";
	}
		//删除帖子
		Tiezi tiezi=new Tiezi();
		tiezi.setCreateuserid(id);
		List<Tiezi> listtiezi = tieziDao.select(tiezi);
		for (Tiezi tiezi2 : listtiezi) {
			//删除帖子下所有回复
			huifuDao.deletebytiezi(tiezi2.getId());
			//删除帖子下所有图片
			picDao.deletebytieziid(tiezi2.getId());
			//删除帖子自己
			tieziDao.delete(tiezi2.getId());
		}
		huifuDao.deletebycreateuserid(id);
		tieziDao.updatetiezilasthuifuidall();
		new IndexThread().start();
		//少一个积分表 在考虑是否删除
		
		return true;
	}
	
	
}

/*
 * 登陆
 * 
				String[] split=urlsplit[1].split("\\.", -1);
				if(split[1].equalsIgnoreCase(PublicStatic.HTML)){
					split=split[0].split("_", -1);
					if(split.length==2){
						url="/member/index.do?id="+split[0]+"&flag="+split[1];
					}else{
						url="/member/index.do?id="+split[0]+"&flag="+split[1]+"&pagestart="+split[2];
					}
					
				}
			}else if("file".equals(urlsplit[0])){
				System.out.println(urlsplit[0]);
			}else{
				String path=request.getServletPath();
				Integer id=isbankuai(path);
				if(id!=null){
					String[] split=urlsplit[1].split("\\.", -1);
					if(split[1].equalsIgnoreCase(PublicStatic.HTML)){
						split=split[0].split("_", -1);
						url="/bk/index.do?bankuaiid="+id+"&pagestart="+split[0]+"&zhutiid="+split[1]+"&orderby="+split[2]+"";
					}
				}
			}
		}
		
		if(!"".equals(url)){
			request.getRequestDispatcher(url).forward(request, response);
			return;
		}
		chain.doFilter(request, response);
	}
	
	public Integer isbankuai(String path){
		String[] split = path.split("/");
		Integer id=null;
		if(PublicStatic.bankuai!=null&&split.length>=2){
			id = PublicStatic.bankuai.get(split[1]);
		}
		return id;
	}
	}
	
	//跳转到修改页面
	@RequestMapping("toupdateoradd.do")
	public String toupdateoradd(Integer id, Model model) {
		if(id!=null){
			InnerLink innerLink=innerLinkService.findbyid(id);
			model.addAttribute("innerLink", innerLink);
		}
		return "jsp/admin/innerlink/updateoradd";
	}
	//修改或者新增
	@RequestMapping("updateoradd.do")
	public String updateoradd(HttpServletRequest request,InnerLink innerLink) {
		User user=(User)request.getSession().getAttribute(PublicStatic.USER);
		innerLink.setCreateuserid(user.getId());
		innerLink.setIsuse("0");
		innerLink.setType("0");
		innerLink.setCreatetime(Tool.getyyyyMMddHHmmss());
		String innerlinkhtml = innerLink.getInnerlink();
		if(innerlinkhtml!=null&&innerlinkhtml.length()>0){
			if(!innerlinkhtml.startsWith("http://")||!innerlinkhtml.startsWith("http://")){
				innerlinkhtml="http://"+innerlinkhtml;
				innerLink.setInnerlink(innerlinkhtml);
			}
		}
		
		if(innerLink.getId()!=null){
			innerLinkService.update(innerLink);
		}else{
			innerLinkService.insert(innerLink);
		}
		return "redirect:index.do ";
	}
	//删除
	@ResponseBody
	@RequestMapping("del.do")
	public String del(int id) {
		String result=innerLinkService.delete(id);
		return result;
	}
	//删除
	@ResponseBody
	@RequestMapping("updateuse.do")
	public String updateuse(int id,String use) {
		InnerLink innerLink=new InnerLink();
		innerLink.setId(id);
		innerLink.setIsuse(use);
		innerLink.setCreatetime(Tool.getyyyyMMddHHmmss());
		innerLinkService.update(innerLink);
		new IndexThread().start();
		return "1";
	}
	public void insert(User User) {
		UserDao.insert(User);
	}

	public String delete(Integer id) {
		String result="1";
		UserDao.delete(id);
		return result;
	}
	public void update(User User) {
		UserDao.update(User);
		
	}
	public User findbyid(User User) {
		List<User> list= UserDao.find(User);
		if(list.size()>0){
			User=list.get(0);
		}
		return User;
	}
	
	public List<User> findbyparentId(User User) {
		List<User> list= UserDao.find(User);
		return list;
	}

	public List<User> find(User User) {
		// TODO Auto-generated method stub
		return UserDao.find(User);
	}

	public String isusername(String loginname) {
		String flag="1";
		User user=new User();
		user.setLoginname(loginname);
		List<User> list = UserDao.find(user);
		if(list.size()>0){
			flag="0";
		}
		return flag;
	}
	public String login(User user,HttpServletRequest request) {
					jifen.setType("104");
					jifen.setContent("每天第一次登录您获得"+PublicStatic.JIFEN_LOGIN+"积分");
					int findnowcount = jifenService.findnowcount(jifen);
					if(findnowcount==0){
						jifenService.insert(jifen);
					}
					Cookie c = new Cookie("login",usersession.getCookieid());
					c.setMaxAge(60*60*24*14);
					c.setPath("/");
					response.addCookie(c);
					if(pathlocation!=null&&!"".equals(pathlocation)){
						try {
							response.sendRedirect(pathlocation);
						} catch (IOException e) {
							e.printStackTrace();
						}
					}else{
						return "redirect:/";
					}
		    	}
		    }
		}
		if(Tool.ismobile(request)){
			return "jsp/mobile/login";
		}else{
			return "jsp/index/login";
		}
	}
	//登录
	@ResponseBody
	@RequestMapping("login.do")
	public Map<String, String> login(HttpServletRequest request,HttpServletResponse response,  User user,String pathlocation,String yanzhengma) {
		if(Tool.isstopip(request, response, 3)){
			return null;
		}
		Map<String, String> map=new HashMap<String, String>();
		HttpSession session = request.getSession(true); 
		String yanzhengmasession=(String)session.getAttribute("yanzhengma");
		String flag="0";
		String msg="0";
		if(!yanzhengma.equalsIgnoreCase(yanzhengmasession)){
			flag="77";
			msg="验证码错误!";
		}else{
			flag=userService.login(user,request);
			if(pathlocation!=null&&!"".equals(pathlocation)){
				map.put("pathlocation", pathlocation);
			}else{
				map.put("pathlocation", request.getContextPath()+"/user/index.do");
			}
		InnerLink innerLink=new InnerLink();
		innerLink.setId(id);
		innerLink.setIsuse(use);
		innerLink.setCreatetime(Tool.getyyyyMMddHHmmss());
		innerLinkService.update(innerLink);
		new IndexThread().start();
		return "1";
	}
	
}

/*
 * 主题的查询
 * 
 */
@Controller
@RequestMapping("/zhuc")
public class ZhucController {

	@Autowired
	UserService userService;
	@Autowired
	GroupService groupService;
	
	 */
	private String getFileExt(String fileName) {
		return fileName.substring(fileName.lastIndexOf("."));
	}

	/**
	 * 依据原始文件名生成新文件名
	 * @return
	 */
	private String getName(String fileName) {
		Random random = new Random();
		return this.fileName = "" + random.nextInt(10000)
				+ System.currentTimeMillis() + this.getFileExt(fileName);
	}

	/**
	 * 根据字符串创建本地目录 并按照日期建立子目录返回
	 * @param path 
	 * @return 
	 */
	private String getFolder(String path) {
		SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
		path += "/" + formater.format(new Date());
		File dir = new File(this.getPhysicalPath(path));
		if (!dir.exists()) {
			try {
				dir.mkdirs();
			} catch (Exception e) {
				this.state = this.errorInfo.get("DIR");
				return "";
			}
		}
		return path;
	}

	/**
	 * 根据传入的虚拟路径获取物理路径
	 * 
	 * @param path
	 * @return
	 */
	private String getPhysicalPath(String path) {
		String servletPath = this.request.getServletPath();
		String realPath = this.request.getSession().getServletContext()
				.getRealPath(servletPath);
		return new File(realPath).getParent() +"/" +path;
	}

	@Autowired
	UserService userService;

	private static Logger log = Logger.getLogger(AdminStopIpController.class);

	//后台页面查询
	@RequestMapping("index.do")
	public String findAllWhere(HttpServletRequest request, Model model,StopIp stopIp,PageBean<StopIp> page) {
		page = stopIpService.findpage(stopIp,page);
		model.addAttribute("page", page);
		return "jsp/admin/stopip/index";
	}
	
	//跳转到修改页面
	@RequestMapping("toupdateoradd.do")
	public String toupdateoradd(StopIp stopIp, Model model) {
		if(stopIp.getId()!=null){
			stopIp=stopIpService.findbyid(stopIp);
		}
		model.addAttribute("stopip", stopIp);
		return "jsp/admin/stopip/updateoradd";
	}
	
	//修改或者新增
	@RequestMapping("updateoradd.do")
	public String updateoradd(HttpServletRequest request,StopIp stopIp) {
		User user=(User)request.getSession().getAttribute(PublicStatic.USER);
		stopIp.setCreateuserid(user.getId());
		stopIp.setCreatetime(Tool.getyyyyMMddHHmmss());
		if(stopIp.getId()!=null){
			stopIpService.update(stopIp);
		}else{
			stopIpService.insert(stopIp);
		}
		new IndexThread().start();
		stopIpService.staticstopip();
		return "redirect:index.do ";
	}
	
	//删除
	@ResponseBody
	@RequestMapping("del.do")
	public String del(int id) {
		String result=stopIpService.delete(id);
		new IndexThread().start();
		stopIpService.staticstopip();
		return result;
	}
	
	//修改生效
	@ResponseBody
				if(user.isIsremember()==true){
					Cookie cookie = new Cookie("javaeelogin",usersession.getCookieid());
					cookie.setMaxAge(60*60*24*14);
					cookie.setPath("/");
					response.addCookie(cookie);
				}
			}
		}
		map.put("flag", flag);
		map.put("msg", msg);
		return map;
	}
}

/*
 * 后台用户管理页面
 * 
 */
@Controller
@RequestMapping("/admin/user")
public class AdminUserContriller {
	
	@Autowired
	UserService userService;
	
	@Autowired
	GroupService groupService;
	
	@Autowired
	JifenGroupService jifenGroupService;
	
	//跳转首页
	@RequestMapping("index.do")
	@RequestMapping("updatestopid.do")
	public String updatestopid(HttpServletRequest request,Integer id) {
		User usersession=(User)request.getSession().getAttribute(PublicStatic.USER);
		User user=new User();
		user.setId(id);
		user = userService.findbyid(user);
		StopIp stopIp=new StopIp();
		stopIp.setStartip(user.getZhuceip());
		stopIp.setEndip(user.getZhuceip());
		stopIp.setIsuse("1");
		stopIp.setType("-2,-3,-4,-5,");
		stopIp.setCreatetime(Tool.getyyyyMMddHHmmss());
		stopIp.setCreateuserid(usersession.getId());
		stopIp.setRemarks("注册IP禁止用户:"+user.getLoginname()+" 注册,登陆,发帖,回复");
		stopIpService.insert(stopIp);
		if(!user.getZhuceip().equals(user.getLoginip())&&user.getLoginip()!=null&&!"".equals(user.getLoginip())){
			stopIp.setStartip(user.getLoginip());
			stopIp.setEndip(user.getLoginip());
			stopIp.setIsuse("1");
			stopIp.setType("-2,-3,-4,-5,");
			stopIp.setCreatetime(Tool.getyyyyMMddHHmmss());
			stopIp.setCreateuserid(usersession.getId());
			stopIp.setRemarks("登陆IP禁止用户:"+user.getLoginname()+" 注册,登陆,发帖,回复");
			stopIpService.insert(stopIp);
		}
		stopIpService.staticstopip();
		return "1";
	}
}


	/**
	 * 文件类型判断
	 * 
	 * @param fileName
	 * @return
	 */
	private boolean checkFileType(String fileName) {
		Iterator<String> type = Arrays.asList(this.allowFiles).iterator();
		while (type.hasNext()) {
			String ext = type.next();
			if (fileName.toLowerCase().endsWith(ext)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 获取文件扩展名
	 * 
	 * @return string
	 */
	private String getFileExt(String fileName) {
		return fileName.substring(fileName.lastIndexOf("."));
	}

	/**
	 * 依据原始文件名生成新文件名
	 * @return
	 */
	private String getName(String fileName) {
		Random random = new Random();
		return this.fileName = "" + random.nextInt(10000)
				+ System.currentTimeMillis() + this.getFileExt(fileName);
	}

	/**
	 * 根据字符串创建本地目录 并按照日期建立子目录返回
	 * @param path 
	 * @return 
	 */
	private String getFolder(String path) {
		SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
		path += "/" + formater.format(new Date());
		File dir = new File(this.getPhysicalPath(path));
		if (!dir.exists()) {
			try {
				dir.mkdirs();
			} catch (Exception e) {
				this.state = this.errorInfo.get("DIR");
		this.request = request;
		HashMap<String, String> tmp = this.errorInfo;
		tmp.put("SUCCESS", "SUCCESS"); //默认成功
		tmp.put("NOFILE", "未包含文件上传域");
		tmp.put("TYPE", "不允许的文件格式");
		tmp.put("SIZE", "文件大小超出限制");
		tmp.put("ENTYPE", "请求类型ENTYPE错误");
		tmp.put("REQUEST", "上传请求异常");
		tmp.put("IO", "IO异常");
		tmp.put("DIR", "目录创建失败");
		tmp.put("UNKNOWN", "未知错误");
		
	}

	public void upload() throws Exception {
		boolean isMultipart = ServletFileUpload.isMultipartContent(this.request);
		if (!isMultipart) {
			this.state = this.errorInfo.get("NOFILE");
			return;
		}
		DiskFileItemFactory dff = new DiskFileItemFactory();
		
		String formater = "/cj" +new SimpleDateFormat("yyyyMMdd").format(new Date());
		dff.setRepository(new File(savePath));
		try {
			ServletFileUpload sfu = new ServletFileUpload(dff);
			sfu.setSizeMax(this.maxSize * 1024);
			sfu.setHeaderEncoding("utf-8");
			FileItemIterator fii = sfu.getItemIterator(this.request);
			while (fii.hasNext()) {
				FileItemStream fis = fii.next();
				if (!fis.isFormField()) {
					this.originalName = fis.getName().substring(fis.getName().lastIndexOf(System.getProperty("file.separator")) + 1);
					if (!this.checkFileType(this.originalName)) {
						this.state = this.errorInfo.get("TYPE");
						continue;
					}
					this.fileName = this.getName(this.originalName);
					this.type = this.getFileExt(this.fileName);
					this.url = this.request.getContextPath()+"/download/downloadimg.do?f="+formater + "/" + this.fileName;
					File files = new File(this.savePath+formater);
            		if (!files.exists()) {
            			files.mkdirs();
            		}
					BufferedInputStream in = new BufferedInputStream(fis.openStream());
					File file = new File(this.savePath+formater+"/"+this.fileName);
					FileOutputStream out = new FileOutputStream( file );
					BufferedOutputStream output = new BufferedOutputStream(out);
					Streams.copy(in, output, true);
					this.state=this.errorInfo.get("SUCCESS");

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值