List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:architecture.ee.web.util.ServletUtils.java
public static String getContextPath(HttpServletRequest request) { if (StringUtils.isEmpty(request.getContextPath())) { return CONTEXT_ROOT_PATH; } else if (StringUtils.equals("/", request.getContextPath().trim())) { return CONTEXT_ROOT_PATH; } else {/*from w w w. j a v a 2s. c o m*/ return request.getContextPath(); } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.LogoutRedirector.java
private static String figureUriFromUrl(HttpServletRequest request, String referrer) { String postContext = breakBeforeContextPath(request.getContextPath(), referrer); String uri = removeQueryString(postContext); log.debug("referrer='" + referrer + "', uri='" + uri + "'"); return uri;/*from ww w. j ava 2 s. c o m*/ }
From source file:com.doculibre.constellio.utils.WebappUtils.java
public static URL getContextPathURL(HttpServletRequest httpRequest) { StringBuffer requestURL = httpRequest.getRequestURL(); String contextPath = httpRequest.getContextPath(); String requestURI = httpRequest.getRequestURI(); String beforeContextPath = StringUtils.substringBefore(requestURL.toString(), requestURI); try {//from w ww . ja v a 2s .c o m return new URL(beforeContextPath + contextPath); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.app.framework.web.mvc.ActionMap.java
public static ActionMap Init(ServletRequest request, ServletResponse response) throws IOException { ActionMap actMap = null;//from w w w.j a v a 2 s . com HttpServletRequest req = ((HttpServletRequest) request); String s1 = req.getContextPath(); String s2 = req.getRequestURI(); String s3 = req.getRequestURL().toString(); String fullUrl = getFullURL(req).toLowerCase(); if (fullUrl.contains(".css") || fullUrl.contains(".js") || fullUrl.contains(".html") || fullUrl.contains(".jpg") || fullUrl.contains(".png") || fullUrl.contains(".gif") || fullUrl.contains(".icon")) { return null; } Gson g = new Gson(); String requestedResource = s2.replace(s1 + "/", ""); String[] urlParts = requestedResource.split("/"); if (urlParts != null && urlParts.length >= 2) { String controller = urlParts[0]; String action = urlParts[1]; String jsonFilePath = req.getServletContext().getRealPath("/WEB-INF/action-map.json"); String json = FileUtils.readFileToString(new File(jsonFilePath), "utf-8"); Type listType = new TypeToken<Map<String, ControllerInfo>>() { }.getType(); Map<String, ControllerInfo> map = g.fromJson(json, listType); String method = req.getMethod(); if (map.containsKey(controller)) { actMap = new ActionMap(); ControllerInfo cInfo = map.get(controller); ActionInfo mInfo = cInfo.getActions().get(action).get(method); actMap.setController(cInfo.getControllerClassName()); actMap.setAction(mInfo.getMethodName()); actMap.setModel(mInfo.getModelClassName()); } } return actMap; }
From source file:com.flowlogix.util.PathUtil.java
/** * Returns full path URI for a relative path * /*from w w w . j a va 2 s . c o m*/ * @param request * @param relativePath * @return relative URI */ @SneakyThrows(URISyntaxException.class) public static URI toAppURI(HttpServletRequest request, String relativePath) { String absolutePath = String.format("%s%s/%s", getServerPath(request), request.getContextPath(), relativePath); return new URI(absolutePath); }
From source file:architecture.ee.web.util.CookieUtils.java
public static void deleteCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie) { if (cookie != null) { String path = request.getContextPath() != null ? request.getContextPath() : "/"; if ("".equals(path)) path = "/"; cookie.setPath(path);//from ww w . j a v a2s . c om cookie.setValue(""); cookie.setMaxAge(0); response.addCookie(cookie); } }
From source file:com.pamarin.income.util.UrlUtils.java
/** * build pattern//from ww w. j a va2s .co m * <ul> * <li>[http|s]://[domainName]:[port]/[contextRoot]</li> * <li>http://pamarin.com/</li> * <li>http://localhost:8080/</li> * <li>http://localhost/pamarin</li> * </ul> * ignore port 80 and 443 * * @param request * @return */ public static String buildHostUrl(HttpServletRequest request) { String contextPath = request.getContextPath(); String protocol = request.getScheme(); String domain = request.getServerName(); String port = request.getServerPort() + ""; port = isReservePort(port) ? "" : (":" + port); return protocol + "://" + domain + port + contextPath; }
From source file:com.manydesigns.elements.servlet.ServletUtils.java
/** * Returns the requested path, without the context path. E.g. webapp deployed under /foo, GET /foo/bar/baz?q=1&k=2, * getPath() returns /bar/baz.//w w w . ja v a2 s . c om * @param request the HTTP request * @return the path of the requested resource as a path internal to the webapp. */ public static String getPath(HttpServletRequest request) { String path = request.getRequestURI(); String contextPath = request.getContextPath(); if (path.startsWith(contextPath)) { path = path.substring(contextPath.length()); } return path; }
From source file:ke.alphacba.cms.core.util.RequestUtils.java
/** * ??,?uri//from www.ja v a2 s.c om * * @param suffix * @return */ public static String getUriBody(HttpServletRequest request, String suffix) { return request.getRequestURI().replace(request.getContextPath() + "/", "").replace(suffix, ""); }
From source file:com.excilys.ebi.bank.web.tld.Functions.java
public static String ctx() { HttpServletRequest request = ServletRequestAttributes.class .cast(RequestContextHolder.getRequestAttributes()).getRequest(); return request.getContextPath(); }