List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:net.sourceforge.fenixedu.presentationTier.Action.utils.RequestUtils.java
public static void sendLoginRedirect(HttpServletRequest request, HttpServletResponse response) throws IOException { response.sendRedirect(request.getContextPath() + "/login"); }
From source file:io.hops.hopsworks.common.util.FormatUtils.java
public static String getUserURL(HttpServletRequest req) { String domain = req.getRequestURL().toString(); String cpath = req.getContextPath(); return domain.substring(0, domain.indexOf(cpath)); }
From source file:net.geoprism.SystemLogoSingletonDTO.java
public static final String getImagesTempDir(HttpServletRequest request) { return request.getContextPath() + "/" + IMAGES_TEMP_DIR + "/"; }
From source file:ServletUtils.java
/** * NOT UNIT TESTED Returns the base url (e.g, <tt>http://myhost:8080/myapp</tt>) suitable for * using in a base tag or building reliable urls. *///from ww w.jav a 2 s . c o m public static String getBaseUrl(HttpServletRequest request) { if ((request.getServerPort() == 80) || (request.getServerPort() == 443)) return request.getScheme() + "://" + request.getServerName() + request.getContextPath(); else return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); }
From source file:com.vmware.demo.ListController.java
public static String getURLWithContextPath(HttpServletRequest request) { return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/sso"; }
From source file:architecture.ee.web.util.CookieUtils.java
public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, int maxAge) { if (value == null) value = ""; String path = request.getContextPath() != null ? request.getContextPath() : "/"; if ("".equals(path)) path = "/"; Cookie cookie = new Cookie(name, value); cookie.setMaxAge(maxAge);/*from ww w. j a va 2 s . co m*/ cookie.setPath(path); response.addCookie(cookie); }
From source file:com.jjtree.utilities.JServeletManager.java
public static JSONObject fetchFrom(HttpServletRequest request, String url) { JSONObject object = null;/* w w w . j a va 2s .co m*/ try { String serverName = request.getServerName(); int portNumber = request.getServerPort(); String contextPath = request.getContextPath(); String accountUrl = "http://" + serverName + ":" + portNumber + contextPath + url; URL urldemo = new URL(accountUrl); URLConnection urlCon = urldemo.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlCon.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { object = new JSONObject(inputLine); } in.close(); } catch (Exception e) { System.out.println(e); } return object; }
From source file:com.jsqlboxdemo.dispatcher.Dispatcher.java
public static void dispach(PageContext pageContext) throws Exception { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String uri = StringUtils.substringBefore(request.getRequestURI(), "."); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath)) uri = StringUtils.substringAfter(uri, contextPath); if (StringUtils.isEmpty(uri) || "/".equals(uri)) uri = "/home"; String[] paths = StringUtils.split(uri, "/"); String[] pathParams;//w ww . j a va2 s . c o m String resource = null; String operation = null; if (paths.length >= 2) {// /team/add/100... resource = paths[0]; operation = paths[1]; pathParams = new String[paths.length - 2]; for (int i = 2; i < paths.length; i++) pathParams[i - 2] = paths[i]; } else { // /home_default resource = paths[0]; pathParams = new String[0]; } if (operation == null) operation = "default"; StringBuilder controller = new StringBuilder("com.jsqlboxdemo.controller.").append(resource).append("$") .append(resource).append("_").append(operation); if ("POST".equals(request.getMethod())) controller.append("_post"); WebBox box; try { Class boxClass = Class.forName(controller.toString()); box = BeanBox.getPrototypeBean(boxClass); } catch (Exception e) { throw new ClassNotFoundException("There is no WebBox classs '" + controller + "' found."); } request.setAttribute("pathParams", pathParams); box.show(pageContext); }
From source file:com.opendesign.utils.ControllerUtil.java
public static String getHostName(HttpServletRequest request) { String scheme = request.getScheme(); String serverName = request.getServerName(); int portNumber = request.getServerPort(); String contextPath = request.getContextPath(); String host = scheme + "://" + serverName + contextPath + ":" + portNumber; if (portNumber == 80) { host = scheme + "://" + serverName + contextPath; }/*from w ww . ja va2 s.c o m*/ return host; }
From source file:ServletUtils.java
/** * NOT UNIT TESTED Returns the URL (including query parameters) minus the scheme, host, and * context path. This method probably be moved to a more general purpose * class./*from ww w .j a va 2s. c o m*/ */ public static String getRelativeUrl(HttpServletRequest request) { String baseUrl = null; if ((request.getServerPort() == 80) || (request.getServerPort() == 443)) baseUrl = request.getScheme() + "://" + request.getServerName() + request.getContextPath(); else baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); StringBuffer buf = request.getRequestURL(); if (request.getQueryString() != null) { buf.append("?"); buf.append(request.getQueryString()); } return buf.substring(baseUrl.length()); }