List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:de.blizzy.documentr.web.Functions.java
public static String getPageHtml(String projectName, String branchName, String path) throws IOException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest();/*from w w w .ja v a 2s. c o m*/ String contextPath = request.getContextPath(); String html = pageRenderer.getHtml(projectName, branchName, path, authentication, contextPath); return markdownProcessor.processNonCacheableMacros(html, projectName, branchName, path, authentication, contextPath); }
From source file:de.blizzy.documentr.web.Functions.java
public static String getPageHeaderHtml(String projectName, String branchName, String path) throws IOException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest();//from ww w .j a v a 2 s.c om String contextPath = request.getContextPath(); String html = pageRenderer.getHeaderHtml(projectName, branchName, path, authentication, contextPath); return markdownProcessor.processNonCacheableMacros(html, projectName, branchName, path, authentication, contextPath); }
From source file:de.kurashigegollub.dev.gcatest.Utils.java
/** * /*www. java 2s.com*/ * Will return a String with the request URL. * @param req The current HttpServletRequest. * @param includeServlet Will include the servlet name in the return value. * @param includePathInfo Will include the path and query parts in the return value (only added, if includeServlet is true as well). * @return */ // http://hostname.com:80/appname/servlet/MyServlet/a/b;c=123?d=789 public static String reconstructURL(HttpServletRequest req, boolean includeServlet, boolean includePathInfo) { String scheme = req.getScheme(); // http String serverName = req.getServerName(); // hostname.com int serverPort = req.getServerPort(); // 80 String contextPath = req.getContextPath(); // /appname String servletPath = req.getServletPath(); // /servlet/MyServlet String pathInfo = req.getPathInfo(); // /a/b;c=123 String queryString = req.getQueryString(); // d=789 // Reconstruct original requesting URL String url = scheme + "://" + serverName + ":" + serverPort + contextPath; if (includeServlet) { url += servletPath; if (includePathInfo) { if (pathInfo != null) { url += pathInfo; } if (queryString != null) { url += "?" + queryString; } } } return url; }
From source file:io.lavagna.web.helper.UserSession.java
private static void addRememberMeCookie(int userId, HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { String token = userRepository.createRememberMeToken(userId); ///*from w ww .j a v a2 s . com*/ Cookie c = new Cookie("LAVAGNA_REMEMBER_ME", userId + "," + token); c.setPath(req.getContextPath() + "/"); c.setHttpOnly(true); c.setMaxAge(60 * 60 * 24 * 365); // 1 year if (req.getServletContext().getSessionCookieConfig().isSecure()) { c.setSecure(true); } resp.addCookie(c); }
From source file:dk.dma.msinm.common.util.WebUtils.java
/** * Returns the base URL of the request//from w w w. j a va2 s . c om * @param request the request * @return the base URL */ public static String getWebAppUrl(HttpServletRequest request, String... appends) { String result = String.format("%s://%s%s%s", request.getScheme(), request.getServerName(), request.getServerPort() == 80 || request.getServerPort() == 443 ? "" : ":" + request.getServerPort(), request.getContextPath()); for (String a : appends) { result = result + a; } return result; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet.java
/** * Logged in, but with insufficient authorization. Send them to the home page * with a message. They won't be coming back. *//*from w w w.j a v a 2s . co m*/ public static void redirectToInsufficientAuthorizationPage(HttpServletRequest request, HttpServletResponse response) { try { DisplayMessage.setMessage(request, I18n.bundle(request).text("insufficient_authorization")); response.sendRedirect(request.getContextPath()); } catch (IOException e) { log.error("Could not redirect to show insufficient authorization."); } }
From source file:com.netsteadfast.greenstep.util.ApplicationSiteUtils.java
@SuppressWarnings("unchecked") public static String getBasePath(String sysId, HttpServletRequest request) { String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; if (StringUtils.isBlank(sysId)) { return basePath; }//from w w w . ja va2s.com ISysService<SysVO, TbSys, String> sysService = (ISysService<SysVO, TbSys, String>) AppContext .getBean("core.service.SysService"); SysVO sys = new SysVO(); sys.setSysId(sysId); try { DefaultResult<SysVO> result = sysService.findByUK(sys); if (result.getValue() == null) { return basePath; } sys = result.getValue(); basePath = request.getScheme() + "://" + sys.getHost() + "/" + sys.getContextPath() + "/"; } catch (ServiceException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return basePath; }
From source file:de.laures.cewolf.taglib.tags.ChartImgTag.java
/** * Fix an absolute url given as attribute by adding the full application url path to it. * It is considered absolute url (not relative) when it starts with "/" * @param url The url to fix/*from ww w . j a va 2 s . c o m*/ * @param request The http request * @return Fixed url contains the full path */ public static String fixAbsolutURL(String url, HttpServletRequest request) { if (url.startsWith("/")) { //final HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); final String context = request.getContextPath(); url = context + url; } return url; }
From source file:com.ineunet.knife.upload.WebPaths.java
/** * @param request HttpServletRequest//from w w w. ja v a 2s .c om */ public static void init(HttpServletRequest request) { if (request == null) { return; } if (inited) return; // init rootUrl String reqUrl = request.getRequestURL().toString(); String reqUri = request.getRequestURI(); int index = reqUrl.length() - reqUri.length(); rootUrl = reqUrl.substring(0, index) + request.getContextPath(); // init rootPath rootPath = request.getSession().getServletContext().getRealPath("/"); // set flag inited = true; }
From source file:com.manydesigns.elements.servlet.ServletUtils.java
public static String getApplicationBaseUrl(HttpServletRequest req) { String scheme = req.getScheme(); int port = req.getServerPort(); String portString;/* w w w . j av a2s.c o m*/ if ((scheme.equals("http") && port == 80) || (scheme.equals("https") && port == 443)) { portString = ""; } else { portString = ":" + port; } return scheme + "://" + req.getServerName() + portString + req.getContextPath(); }