标签:highlight obj appname username upload let param front drs
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); response.setHeader("Access-Control-Allow-Origin", "*"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); JSONObject resultJson = new JSONObject(); int maxPostSize = 1 * 100 * 1024 * 1024; String appname = ""; String applyid = ""; String applytel = ""; String appcard = ""; String addrss = ""; String detailaddress = ""; File previewImg3 = null; File previewImg1 = null; File previewImg2 = null; String userNo = (String)request.getSession().getAttribute("userNameFront"); String fwpath="D:\\temp\\aaa\\bb\\"; CreateSerialNumber createSerialNumber =new CreateSerialNumber(); String uuID = createSerialNumber.createOrderSn(); DBTools dbTools = new DBTools("qrcode"); TResercardMapper tResercardMapper = dbTools.createMapper(TResercardMapper.class); TResercard tResercard = new TResercard(); Date nowDate = new Date(); String contentType = request.getContentType(); if (contentType != null && contentType.contains("multipart/form-data")) { // 将转化后的 request 放入过滤链中 MultipartRequest mulitReq=new MultipartRequest(request,"D:/upload_test11/",maxPostSize,"utf-8"); previewImg3 = mulitReq.getFile("previewImg3");//读文件 文件的name previewImg2 = mulitReq.getFile("previewImg2");//读文件 文件的name previewImg1 = mulitReq.getFile("previewImg1");//读文件 文件的name appname = mulitReq.getParameter("appname"); applyid = mulitReq.getParameter("applyid") == null ? null : mulitReq.getParameter("applyid").toString(); //读文本框里 input框的name applytel = mulitReq.getParameter("applytel") == null ? null : mulitReq.getParameter("applytel").toString();//读文本框里 input框的name appcard = mulitReq.getParameter("appcard") == null ? null : mulitReq.getParameter("appcard").toString();//读文本框里 input框的name addrss = mulitReq.getParameter("addrss") == null ? null : mulitReq.getParameter("addrss").toString();//读文本框里 input框的name detailaddress = mulitReq.getParameter("detailaddress") == null ? null : mulitReq.getParameter("detailaddress").toString(); } Syslog.info("DBToolst nowDate qrcode"); tResercard.setUuid(uuID); tResercard.setAddress(addrss); tResercard.setAddressdetail(detailaddress); tResercard.setUserno(userNo); tResercard.setApplyname(appname); tResercard.setApplyid(applyid); tResercard.setApplytel(applytel); tResercard.setApplycardtype(appcard); tResercard.setApplytime(nowDate); Syslog.info("Syslog++++addDaMengXiaomCard+++++出去了了"); System.out.println("tResercard.toString()"); System.out.println(tResercard.toString()); Syslog.info(tResercard.toString()); int insertNumber = tResercardMapper.insertSelective(tResercard); if(insertNumber == 1) { Syslog.info("成功插入数据:----"+insertNumber); resultJson.put("code", "0000"); resultJson.put("msg", "success"); }else { resultJson.put("code", "1111"); resultJson.put("msg", "插入数据库失败"); } dbTools.closeSqlSession(); out.println(resultJson); out.close(); }
此种方法可以将form表单中的文本 和图片信息进行分离读取;
文件会在运行
new MultipartRequest(request,"D:/upload_test11/",maxPostSize,"utf-8")
;
构造器是自动分离文本和文件;并将文件读到 设置的路径中,
form表单提交信息(包含文字以及照片信息)使用MultipartRequest进行读取
标签:highlight obj appname username upload let param front drs
原文地址:https://www.cnblogs.com/cjeandailynotes/p/10855913.html