List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:gov.nih.nci.ncicb.cadsr.cdebrowser.servlets.SessionFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException { String expiredSessionJSP = filterConfig.getInitParameter("expiredSessionJSP"); //String controller = filterConfig.getInitParameter("controllerName"); HttpServletRequest req = (HttpServletRequest) request; //Object param = request.getParameter("FirstTimer"); String param = request.getParameter("FirstTimer"); HttpSession userSession = req.getSession(false); if (param == null && userSession == null) { ((HttpServletResponse) response).sendRedirect(req.getContextPath() + expiredSessionJSP); return;//from www . j ava 2s . c o m } chain.doFilter(request, response); }
From source file:com.ace.erp.controller.sys.company.OrganizationController.java
@RequestMapping(value = "/company/uploadLogo", method = RequestMethod.POST) @ResponseBody//from w w w.jav a 2 s . c o m public Response uploadLogo(@CurrentUser User user, String srcImageFile, int x, int y, int destWidth, int destHeight, int srcShowWidth, int srcShowHeight, HttpServletRequest request) { try { String path = request.getSession().getServletContext().getRealPath("/"); String contextPath = request.getContextPath(); Image img; ImageFilter cropFilter; //String srcFileName = FilenameUtils.getName(srcImageFile); String srcFileName = StringUtils.isNotBlank(contextPath) ? srcImageFile.replaceFirst(contextPath, "") : srcImageFile; // ??? File srcFile = new File(path + "/" + srcFileName); BufferedImage bi = ImageIO.read(srcFile); //?????????? int srcWidth = bi.getWidth(); // ? int srcHeight = bi.getHeight(); // ? if (srcShowWidth == 0) srcShowWidth = srcWidth; if (srcShowHeight == 0) srcShowHeight = srcHeight; if (srcShowWidth >= destWidth && srcShowHeight >= destHeight) { //??? Image image = bi.getScaledInstance(srcShowWidth, srcShowHeight, Image.SCALE_DEFAULT); cropFilter = new CropImageFilter(x, y, destWidth, destHeight); img = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(image.getSource(), cropFilter)); BufferedImage tag = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(img, 0, 0, null); // ?? g.dispose(); String ext = FilenameUtils.getExtension(srcImageFile); //path += HEADER_PIC; //User loginUser = SystemUtil.getLoginUser(request.getSession()); //String fileName = user.getOrganizationList().get(0).getId()+""; File destImageFile = new File(path + "/" + System.currentTimeMillis() + ".jpg"); // ImageIO.write(tag, ext, destImageFile); //loginUser.setPicPath(SystemConst.SYSTEM_CONTEXT_PATH_VALUE + HEADER_PIC + "/" + fileName); //userService.update(loginUser); // srcFile.delete(); return new Response(new ResponseHeader(200, 20)); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.filter.HaveUserRecordFilter.java
private void sendForbiddenError(HttpServletResponse servletResponse, HttpServletRequest servletRequest, boolean created) throws IOException { if (this.properties.isRegistrationEnabled()) { servletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN); if (created) { servletResponse.sendRedirect(servletRequest.getContextPath() + "/logout?awaitingActivation=true"); } else {/*from www . jav a 2s . c om*/ servletResponse.sendRedirect(servletRequest.getContextPath() + "/logout?notRegistered=true"); } } else { servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); } }
From source file:cn.guoyukun.spring.web.controller.KindEditorController.java
private String successResponse(HttpServletRequest request, String filename, String url) { return "{\"error\":0, \"url\":\"" + request.getContextPath() + "/" + url + "\", \"title\":\"" + filename + " \"}"; }
From source file:vmware.au.se.sqlfireweb.controller.MemberController.java
@RequestMapping(value = "/members", method = RequestMethod.GET) public String showDiskstores(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { javax.servlet.jsp.jstl.sql.Result allMemberInfoResult = null; if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/sqlfireweb/login"); return null; }/*from w ww .jav a2s .c o m*/ logger.debug("Received request to show members"); MemberDAO mbrDAO = ISQLFireDAOFactory.getMemberDAO(); String memberAction = request.getParameter("memberAction"); if (memberAction != null) { logger.debug("memberAction = " + memberAction); if (memberAction.equals("ALLMEMBEREVENTINFO")) { allMemberInfoResult = mbrDAO.getMemberInfo((String) request.getParameter("memberId"), (String) session.getAttribute("user_key")); model.addAttribute("allMemberInfoResult", allMemberInfoResult); model.addAttribute("memberid", (String) request.getParameter("memberId")); } } List<Member> members = mbrDAO.retrieveMembers((String) session.getAttribute("user_key")); model.addAttribute("members", members); model.addAttribute("records", members.size()); model.addAttribute("estimatedrecords", members.size()); // This will resolve to /WEB-INF/jsp/members.jsp return "members"; }
From source file:com.liusoft.dlog4j.upload.SecurityFCKUploadServlet.java
/** * ?WAP/*from w w w .ja va2 s . co m*/ */ protected void makeOutput(HttpServletRequest req, HttpServletResponse res, Hashtable params, String msg) throws IOException { String toPage = (String) params.get("toPage"); if (StringUtils.isEmpty(toPage)) { super.makeOutput(req, res, params, msg); } else { res.sendRedirect(req.getContextPath() + toPage); } }
From source file:com.expressflow.interceptors.SessionInterceptor.java
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // Checking expressBPEL Session logger.info("Checking User Session"); User user = (User) request.getSession().getAttribute(Constants.SESSION_USER); String uri = request.getRequestURI(); String base = request.getContextPath(); uri = uri.substring(base.length());/*from w w w . j a va 2 s. co m*/ if (user == null && !uri.startsWith("/api/login")) { // Check Google App Engine User Service logger.info("Checking Google App Engine User Service"); UserService userService = UserServiceFactory.getUserService(); com.google.appengine.api.users.User googleUser = userService.getCurrentUser(); if (googleUser != null) { logger.info("Email: " + googleUser.getEmail() + "\t Nickname: " + googleUser.getNickname()); } if (googleUser == null) { logger.info("All checks failed. Invalidating session."); response.sendRedirect(userService.createLoginURL(request.getRequestURI())); return false; } } return true; }
From source file:net.sibcolombia.portal.web.tag.AlphabetLinkTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() *//* ww w.j ava2 s. c om*/ @Override public int doStartTag() throws JspException { Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest()); if (letters == null || letters.isEmpty()) { return super.doStartTag(); } StringBuffer sb = new StringBuffer(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String contextPath = request.getContextPath(); List<Character> ignoreChars = new ArrayList<Character>(); if (StringUtils.isNotEmpty(ignores)) { ignores = ignores.trim(); StringTokenizer st = new StringTokenizer(ignores); while (st.hasMoreTokens()) { String ignoreChar = st.nextToken(); if (ignoreChar.length() != 1) { throw new JspException("Invalid ignore list :" + ignoreChar); } ignoreChars.add(new Character(ignoreChar.charAt(0))); } } sb.append("<ul class=\""); sb.append(listClass); sb.append("\">"); sb.append("<li class=\"lt\">"); letters.add(0, '0'); int indexOfSelected = letters.indexOf(selected); if (indexOfSelected > 0) { addLink(sb, contextPath, letters.get(indexOfSelected - 1), "<<"); } else { sb.append("<<"); } sb.append("</li>"); List<String> acceptedChars = Arrays.asList(accepted); for (Character letter : letters) { if (!ignoreChars.contains(letter) && acceptedChars.contains(letter.toString())) { sb.append("<li"); if (!(letter == '0')) { if (selected != letter) { sb.append('>'); addLink(sb, contextPath, letter); } else { sb.append(" id=\"chosen\">"); sb.append(letter); } } else { if (selected != letter) { sb.append('>'); addLink(sb, contextPath, '0', messageSource.getMessage("dataset.list.showall", null, "Todas", locale)); } else { sb.append(" id=\"chosen\">"); sb.append(messageSource.getMessage("dataset.list.showall", null, "Todas", locale)); } } sb.append("</li>"); } } sb.append("<li class=\"lt\">"); if (indexOfSelected < (letters.size() - 1)) { addLink(sb, contextPath, letters.get(indexOfSelected + 1), ">>"); } else { sb.append(">>"); } sb.append("</li>"); sb.append("</ul>"); try { pageContext.getOut().write(sb.toString()); } catch (IOException e) { throw new JspException(e); } return super.doStartTag(); }
From source file:net.groupbuy.controller.shop.LoginController.java
/** * ?//from w w w. ja v a2s .c o m */ @RequestMapping(method = RequestMethod.GET) public String index(String redirectUrl, HttpServletRequest request, ModelMap model) { Setting setting = SettingUtils.get(); if (redirectUrl != null && !redirectUrl.equalsIgnoreCase(setting.getSiteUrl()) && !redirectUrl.startsWith(request.getContextPath() + "/") && !redirectUrl.startsWith(setting.getSiteUrl() + "/")) { redirectUrl = null; } model.addAttribute("redirectUrl", redirectUrl); model.addAttribute("captchaId", UUID.randomUUID().toString()); return "/shop/login/index"; }