java表单处理带文件的处理 对文件过滤处理
来源:互联网 发布:windows系统官网下载 编辑:程序博客网 时间:2024/05/20 10:15
package com.xiong.mendianfu.controllers;import com.xiong.mendianfu.bean.PageList;import com.xiong.mendianfu.bean.QiyeBean;import com.xiong.mendianfu.services.QiyeService;import com.xiong.mendianfu.services.impl.QiyeServiceImpl;import org.apache.commons.fileupload.FileItem;import org.apache.commons.fileupload.FileUploadException;import org.apache.commons.fileupload.disk.DiskFileItemFactory;import org.apache.commons.fileupload.servlet.ServletFileUpload;import org.apache.commons.io.FilenameUtils;import org.apache.commons.io.IOUtils;import org.apache.commons.lang3.StringUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.*;/** *企业信息管理 */@Controller@RequestMapping("/qiye")public class QiyeController { @Resource private QiyeServiceImpl qiyeService; @RequestMapping("/createqiye") public ModelAndView create(HttpServletRequest request, HttpServletResponse response){ ModelAndView mv=new ModelAndView(); DiskFileItemFactory factory=new DiskFileItemFactory(); ServletFileUpload upload=new ServletFileUpload(factory); try{ Map<String,String> result=new HashMap<String,String>(); List<FileItem> items = upload.parseRequest(request); for(FileItem item:items){ if(!item.isFormField()){ //将文件内容保存到磁盘上。 String path="/upload"; //获取真实路径 path=request.getSession().getServletContext().getRealPath(path); String filename=""; filename=item.getName();//原始文件名 filename=(new Date()).getTime()+"." + FilenameUtils.getExtension(filename); //文件重命名 FileOutputStream os = new FileOutputStream(path+ File.separator+filename); if(filename.endsWith(".jpg")){ IOUtils.copy(item.getInputStream(),os); os.flush(); os.close(); result.put(item.getFieldName(),"/upload/"+filename); }else { mv.addObject("loginInfo", "添加 失败"); mv.addObject("nextUrl", request.getContextPath() + "/index.jsp"); mv.setViewName("/msg.jsp"); return mv; } }else{ result.put(item.getFieldName(), IOUtils.toString(item.getInputStream(),"utf-8")) ; } } QiyeBean qiyeBean=new QiyeBean(); String uuid =UUID.randomUUID().toString().replace("-", ""); qiyeBean.setQiyeid(uuid); qiyeBean.setMingcheng(result.get("mingcheng")); qiyeBean.setDizhi(result.get("dizhi")); qiyeBean.setDianhua(result.get("dianhua")); qiyeBean.setWxsubappid(result.get("wxsubappid")); qiyeBean.setWxsubmchid(result.get("wxsubmchid")); qiyeBean.setAdminopenid(result.get("openid")); qiyeBean.setAlipaysubmchid(result.get("aplipaysubchid")); qiyeBean.setAlipayzhanghao(result.get("aplipayzhanghao")); qiyeBean.setAlipaysubappid(result.get("aplipaysubappid")); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date date = sdf.parse(result.get("shijian").toString().replaceAll("-","")); qiyeBean.setQianyue(date); qiyeBean.setBeizhu(result.get("beizhu")); qiyeBean.setYingyezhizhao(result.get("fujian")); qiyeBean.setKaihuhang(result.get("kaihuhang")); qiyeBean.setZhanghao(result.get("zhanghao")); boolean results = qiyeService.create(qiyeBean); if(results){ mv.addObject("loginInfo", "添加成功"); mv.addObject("nextUrl", request.getContextPath() + "/index.jsp"); }else { mv.addObject("loginInfo", "添加失败"); mv.addObject("nextUrl", request.getContextPath() + "/index.jsp"); } } catch (FileUploadException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } mv.setViewName("/msg.jsp"); return mv; } }
package com.xiong.mendianfu.services.impl;import com.xiong.mendianfu.bean.PageList;import com.xiong.mendianfu.bean.QiyeBean;import com.xiong.mendianfu.dao.QiYeDao;import com.xiong.mendianfu.services.QiyeService;import com.xiong.mendianfu.services.CommonCRUDService;import org.springframework.stereotype.Service;import javax.annotation.Resource;import java.math.BigDecimal;import java.util.HashMap;import java.util.List;import java.util.Map;@Servicepublic class QiyeServiceImpl implements QiyeService, CommonCRUDService { @Resource QiYeDao qiYeDao;/** *@see com.xiong.mendianfu.services.QiyeService#updateAdmin(int, String) */public boolean updateAdmin(String qiyeid, String openid){int result=0;Map map=new HashMap();map.put("qiyeid",qiyeid);map.put("openid",openid);result= qiYeDao.updateAdmin(map);return result>0;} /** *@see com.xiong.mendianfu.services.CommonCRUDService#create(Object) */public boolean create(Object obj){int result=0;result= qiYeDao.create((QiyeBean ) obj);return result>0;} }
<%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/11/27 Time: 15:47 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ include file="../int/top.jsp"%><div class="row"> <div class="col-xs-2"></div><div class="col-xs-6"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <form action="<%=ctxpath%>/qiye/createqiye.do" enctype="multipart/form-data" method="post"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="mingcheng" placeholder="请输入企业名称"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="dizhi" placeholder="请输入企业地址"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="dianhua" placeholder="请输入电话"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="wxsubmchid" placeholder="请输入微信商户号"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="wxsubappid" placeholder="请输入微信appid"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="aplipaysubchid" placeholder="请输入支付宝商户号"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="aplipaysubappid" placeholder="请输入支付宝appid"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="aplipayzhanghao" placeholder="请输入支付宝账号"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="shijian" placeholder="请输入签约时间"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="file" id="" name="fujian" placeholder="请输入营业执照"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text"id="" name="zhanghao" placeholder="请输入对公账号"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="kaihuhang" placeholder="请输入开户银行"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="beizhu" placeholder="请输入备注"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <input class="form-control" type="text" id="" name="openid" placeholder="请输入管理员微信号"> <div class="row"> <div class="col-xs-12"><h5></h5></div> </div> <button type="submit" class="btn btn-primary">添加</button> </form></div></div>
0 0
- java表单处理带文件的处理 对文件过滤处理
- VC对读取的每行文件内容的过滤处理
- java对大文件的处理思路
- Java对大文件的处理
- java对文件的处理操作
- java中对文件的处理
- Java对excel文件的处理
- JAVA对excel文件的处理方式
- Java对文件的读写和处理
- Linux下对带空格的文件进行处理
- spring MVC提交处理带文件和非文件表单
- Java 文件的处理
- Java 文件的处理
- PHP对表单提交特殊字符的过滤和处理
- php对表单提交的字符串过滤处理
- PHP对表单提交特殊字符的过滤和处理
- PHP对表单提交特殊字符的过滤和处理
- PHP对表单提交特殊字符的过滤和处理
- 简单介绍下MYSQL的索引类型
- 我的csdn博客积分清零了,博客等级也恢复成了1级,这是怎么回事?
- 关于opencv2和3在图像特征识别的区别。
- spring事务回滚问题
- ListView AsynTask异步加载网络Json格式数据和图片显示的优化
- java表单处理带文件的处理 对文件过滤处理
- Linux-文件默认权限与umask
- C# 根据网址下载网页
- mysql外网无法访问解决思路
- Cocos Creator中获取和加载资源(官方文档摘录)
- 大日志文件分割
- ROS Navigation-----costmap_2d之staticmap层简介
- CDH中的Solr中文分词
- hdu2053 Switch Game