/** 这个方法非常重要,重写计算缓存key的方法,没有该方法include的url值会出错 */ @Override protected String calculateKey(HttpServletRequest httpRequest) { // TODO Auto-generated method stub String url = httpRequest.getRequestURI(); String include_url = CommUtil.null2String(httpRequest.getAttribute("javax.servlet.include.request_uri")); StringBuffer stringBuffer = new StringBuffer(); if (include_url.equals("")) { stringBuffer.append(httpRequest.getRequestURI()).append(httpRequest.getQueryString()); String key = stringBuffer.toString(); return key; } else { stringBuffer .append( CommUtil.null2String(httpRequest.getAttribute("javax.servlet.include.request_uri"))) .append( CommUtil.null2String(httpRequest.getAttribute("javax.serlvet.include.query_string"))); String key = stringBuffer.toString(); return key; } }
@Override protected void doFilter( final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws AlreadyGzippedException, AlreadyCommittedException, FilterNonReentrantException, LockTimeoutException, Exception { if (cacheURLs == null || cacheURLs.size() < 1) { init(); } String url = request.getRequestURI(); String include_url = CommUtil.null2String(request.getAttribute("javax.servlet.include.request_uri")); boolean flag = false; /* if(url.contains("floor.htm")){ StringBuffer url_param = request.getRequestURL(); if (request.getQueryString() != null) { url_param.append("?"); url_param.append(request.getQueryString()); } System.out.println(url_param.toString()); // 获取cookies String pc_city_id = CommonUtils.getCityIdFromCookies(request); url=url+"?city_id="+pc_city_id; System.out.println(pc_city_id); if(!cacheURLs.contains(url)){//不包含 cacheURLs.add(url); } }*/ if (cacheURLs != null && cacheURLs.size() > 0) { for (String cacheURL : cacheURLs) { if (include_url.trim().equals("")) { if (url.contains(cacheURL.trim())) { flag = true; break; } } else { if (include_url.contains(cacheURL.trim())) { flag = true; break; } } } } // 如果包含我们要缓存的url 就缓存该页面,否则执行正常的页面转向 if (flag) { super.doFilter(request, response, chain); } else { chain.doFilter(request, response); } }
/** * watermark保存管理 * * @param id * @return */ @SecurityMapping( title = "图片水印保存", value = "/seller/watermark_save.htm*", rtype = "seller", rname = "图片管理", rcode = "album_seller", rgroup = "其他设置") @RequestMapping("/seller/watermark_save.htm") public ModelAndView watermark_save( HttpServletRequest request, HttpServletResponse response, String id, String currentPage, String cmd) { ModelAndView mv = null; if (SecurityUserHolder.getCurrentUser().getStore() != null) { WebForm wf = new WebForm(); WaterMark watermark = null; if (id.equals("")) { watermark = wf.toPo(request, WaterMark.class); watermark.setAddTime(new Date()); } else { WaterMark obj = this.watermarkService.getObjById(Long.parseLong(id)); watermark = (WaterMark) wf.toPo(request, obj); } watermark.setStore(SecurityUserHolder.getCurrentUser().getStore()); String path = request.getSession().getServletContext().getRealPath("/") + "upload/wm"; try { Map map = CommUtil.saveFileToServer(request, "wm_img", path, null, null); if (!map.get("fileName").equals("")) { Accessory wm_image = new Accessory(); wm_image.setAddTime(new Date()); wm_image.setHeight(CommUtil.null2Int(map.get("height"))); wm_image.setName(CommUtil.null2String(map.get("fileName"))); wm_image.setPath("upload/wm"); wm_image.setSize(CommUtil.null2Float(map.get("fileSize"))); wm_image.setUser(SecurityUserHolder.getCurrentUser()); wm_image.setWidth(CommUtil.null2Int("width")); this.accessoryService.save(wm_image); watermark.setWm_image(wm_image); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (id.equals("")) { this.watermarkService.save(watermark); } else this.watermarkService.update(watermark); mv = new JModelAndView( "success.html", configService.getSysConfig(), this.userConfigService.getUserConfig(), 1, request, response); mv.addObject("op_title", "水印设置成功"); } else { mv = new JModelAndView( "error.html", configService.getSysConfig(), this.userConfigService.getUserConfig(), 1, request, response); mv.addObject("op_title", "您尚未开店"); } mv.addObject("url", CommUtil.getURL(request) + "/seller/watermark.htm"); return mv; }