// 网站信息编辑 if (ac.equals("siteinfoedit")) { String id = request.getParameter("id"); HashMap map = dao.select("select * from siteinfo where id=" + id) .get(0); try { String tel = ""; String addr = ""; String note = ""; String logoimg = map.get("logoimg").toString(); request.setCharacterEncoding("utf-8"); RequestContext requestContext = new ServletRequestContext( request); if (FileUpload.isMultipartContent(requestContext)) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setRepository(new File(request .getRealPath("/upfile/") + "/")); ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(100 * 1024 * 1024); List items = new ArrayList(); items = upload.parseRequest(request); tel = ((FileItem) items.get(0)).getString(); tel = Info.getUTFStr(tel); addr = ((FileItem) items.get(1)).getString(); addr = Info.getUTFStr(addr); note = ((FileItem) items.get(3)).getString(); note = Info.getUTFStr(note); FileItem fileItem = (FileItem) items.get(2); if (fileItem.getName() != null && fileItem.getSize() != 0) { if (fileItem.getName() != null && fileItem.getSize() != 0) { File fullFile = new File(fileItem.getName()); logoimg = Info.generalFileName(fullFile.getName()); File newFile = new File( request.getRealPath("/upfile/") + "/" + logoimg); try { fileItem.write(newFile); } catch (Exception e) { e.printStackTrace(); } } else { } } } String sql = "update siteinfo set tel='" + tel + "',addr='" + addr + "',note='" + note + "',logoimg='" + logoimg + "' where id=" + id; dao.commOper(sql); request.setAttribute("suc", ""); go("/admin/siteinfo.jsp?id=" + id, request, response); } catch (Exception e1) { e1.printStackTrace(); request.setAttribute("error", ""); request.getRequestDispatcher("/admin/siteinfo.jsp?id=" + id) .forward(request, response); } }
时间: 2024-04-27 21:24:23 浏览: 94
网页编辑所需要要的
这段代码是用于处理网站信息编辑的请求。当请求的参数为"siteinfoedit"时,会从请求中获取网站信息的id,并查询数据库获取该信息的详细信息。然后通过解析请求参数,获取修改后的内容,包括电话、地址、备注和logo图片等,并对这些内容进行编码处理。接着,通过判断是否有上传logo图片,如果有则将图片保存到服务器上,同时更新数据库中的网站信息。最后,将处理结果通过请求转发的方式返回给前端页面。需要注意的是,该代码存在SQL注入漏洞和文件上传漏洞,建议使用预编译语句、参数化查询和安全的文件上传方式来避免此类问题。
阅读全文