HttpServletRequest.getServletContext()一直提示找不到

 

转载于:https://www.cnblogs.com/Girlir/p/8987700.html

public Map<String,String> upload(Manuscript manuscript,MultipartFile manuscript_file,HttpServletRequest request, HttpServletResponse response ) throws IOException{ Map<String,String> ret = new HashMap<String,String>(); if(StringUtils.isEmpty(manuscript.getAuthor_name())) { ret.put("type","error"); ret.put("msg","作者姓名不能为空!"); return ret; } String author_name = request.getSession().getAttribute("author_name").toString(); if(!manuscript.getAuthor_name().equals(author_name)) { ret.put("type","error"); ret.put("msg","请输入正确的姓名!"); return ret; } if(StringUtils.isEmpty(manuscript.getTitle())) { ret.put("type","error"); ret.put("msg","稿件标题不能为空!"); return ret; } if(StringUtils.isEmpty(manuscript.getSummary())) { ret.put("type","error"); ret.put("msg","稿件摘要不能为空!"); return ret; } if(manuscript_file==null) { ret.put("type","error"); ret.put("msg","文件没有选择"); return ret; } if(manuscript_file.getSize() > 10485760){ //文件没有选择 ret.put("type", "error"); ret.put("msg", "文件大小超过10M!"); return ret; } String suffix = manuscript_file.getOriginalFilename().substring(manuscript_file.getOriginalFilename().lastIndexOf(".")+1,manuscript_file.getOriginalFilename().length()); if(!"docx,doc,pdf".contains(suffix)) { ret.put("type","error"); ret.put("msg","文件格式不正确!"); return ret; } String savePath = request.getServletContext().getRealPath("/")+"\upload\"; File savePathFile = new File(savePath); if(!savePathFile.exists()) { savePathFile.mkdir(); } String fileName = new Date().getTime()+"."+suffix; ret.put("src",request.getServletContext().getContextPath() + "/upload/" + fileName); manuscript_file.transferTo(new File(savePath+fileName)); manuscript.setFilePath(ret.get("src")); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String format = sf.format(new Date()); manuscript.setSubmit_time(format); manuscript.setId((Integer)request.getSession().getAttribute("id")); manuscript.setState("待审核"); if(authorService.add(manuscript)<=0) { ret.put("type","error"); ret.put("msg","稿件添加失败!"); return ret; } ret.put("type", "success"); ret.put("msg", "文件上传成功!"); return ret; }这段代码什么意思
04-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值