Example usage for javax.servlet.http HttpServletRequest getContextPath

List of usage examples for javax.servlet.http HttpServletRequest getContextPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getContextPath.

Prototype

public String getContextPath();

Source Link

Document

Returns the portion of the request URI that indicates the context of the request.

Usage

From source file:com.concursive.connect.web.portal.PortletManager.java

public static synchronized String checkRegistryService(ServletContext context, ServletConfig config,
        HttpServletRequest request) throws PortletContainerException {
    // Add the registry service which preloads all of the portlets
    String contextPath = (String) context.getAttribute("PortletContextPath");
    if (contextPath == null) {
        PortletContextManager registryService = PortletContextManager.getManager();
        registryService.register(config);
        contextPath = request.getContextPath();
        if (!StringUtils.hasText(contextPath)) {
            // Pluto corrects for using a "/" as the context path
            contextPath = "/";
        }// w ww .j av a 2s.  c om
        context.setAttribute("PortletContextPath", contextPath);
    }
    return contextPath;
}

From source file:com.hp.autonomy.frontend.find.idol.web.IdolErrorController.java

private URI getUrl(final HttpServletRequest request) {
    return URI.create(request.getContextPath() + BASE_SEARCH_URL);
}

From source file:com.tz.core.MyFreeMakerView.java

@Override
protected void exposeHelpers(Map model, HttpServletRequest request) throws Exception {
    model.put(CONTEXT_PATH, request.getContextPath());
    model.put(currentURL, request.getRequestURI());
    super.exposeHelpers(model, request);
}

From source file:com.bstek.dorado.web.resolver.WebContextSupportedController.java

private String getContextPath(HttpServletRequest request) {
    return request.getContextPath();
}

From source file:net.paulgray.mocklti2.web.Lti2ConsumerController.java

@RequestMapping(value = "/")
public String getWelcome(HttpServletRequest request, ModelMap model) {
    model.addAttribute("contextPath", request.getContextPath());
    model.addAttribute("contextUrl", request.getRequestURL());
    model.addAttribute("contextUri", request.getRequestURI());
    return "welcome";
}

From source file:org.netxilia.server.rest.html.GenericHTMLProviderInterceptor.java

@Override
public void intercept(ModelAndView<Object> modelAndView, HttpServletRequest request) {
    request.setAttribute("images", request.getContextPath() + "/images");
    request.setAttribute("css", request.getContextPath() + "/css");
    request.setAttribute("scripts", request.getContextPath() + "/js");
    request.setAttribute(USER, userService.getCurrentUser());
}

From source file:org.opendatakit.dwc.server.GreetingServiceImpl.java

public static String getServerURL(HttpServletRequest req, String relativeServletPath, boolean preserveQS) {
    // for now, only store the servlet context and the serverUrl
    String path = req.getContextPath();

    Integer identifiedPort = req.getServerPort();
    String identifiedHostname = req.getServerName();

    if (identifiedHostname == null || identifiedHostname.length() == 0
            || identifiedHostname.equals("0.0.0.0")) {
        try {/*from w ww  .j  av  a 2  s .c  o  m*/
            identifiedHostname = InetAddress.getLocalHost().getCanonicalHostName();
        } catch (UnknownHostException e) {
            identifiedHostname = "127.0.0.1";
        }
    }

    String identifiedScheme = "http";

    if (identifiedPort == null || identifiedPort == 0) {
        if (req.getScheme().equals(identifiedScheme)) {
            identifiedPort = req.getServerPort();
        } else {
            identifiedPort = HtmlConsts.WEB_PORT;
        }
    }

    boolean expectedPort = (identifiedScheme.equalsIgnoreCase("http") && identifiedPort == HtmlConsts.WEB_PORT)
            || (identifiedScheme.equalsIgnoreCase("https") && identifiedPort == HtmlConsts.SECURE_WEB_PORT);

    String serverUrl;
    if (!expectedPort) {
        serverUrl = identifiedScheme + "://" + identifiedHostname + BasicConsts.COLON
                + Integer.toString(identifiedPort) + path;
    } else {
        serverUrl = identifiedScheme + "://" + identifiedHostname + path;
    }

    String query = req.getQueryString();
    if (query == null) {
        if (req.getServletPath().equals("/demowebclient/greet")) {
            if (CLIENT_WEBSITE_CODESVR_PORT.length() != 0) {
                query = "gwt.codesvr=127.0.0.1:" + CLIENT_WEBSITE_CODESVR_PORT;
            } else {
                query = "";
            }
        } else {
            query = "";
        }
    }

    if (query.length() != 0) {
        query = "?" + query;
    }
    return serverUrl + BasicConsts.FORWARDSLASH + relativeServletPath + (preserveQS ? query : "");
}

From source file:com.uds.sauvage.controller.WelcomeController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
public String listAll(Model model, HttpServletRequest req) {
    System.out.println("Je passe la");
    req.setAttribute("base_url", req.getContextPath());
    model.addAttribute("surveys", surveyService.getAll());
    model.addAttribute("page", "welcome.jsp");
    System.out.println("passage " + req.getContextPath());
    return "index";
}

From source file:org.bonitasoft.web.designer.controller.preview.Previewer.java

/**
 * Determines the resourceContext if it isn't defined
 *//*from w w w  .  ja  v  a 2  s .  co  m*/
private String getResourceContext(HttpServletRequest httpServletRequest) {
    return StringUtils.isEmpty(httpServletRequest.getContextPath()) ? "/runtime/"
            : httpServletRequest.getContextPath() + "/runtime/";
}

From source file:org.geoserver.ows.ClasspathPublisher.java

@Override
protected URL getUrl(HttpServletRequest request) {
    String ctxPath = request.getContextPath();
    String reqPath = request.getRequestURI();
    reqPath = reqPath.substring(ctxPath.length());

    // try a few lookups
    URL url = clazz.getResource(reqPath);
    if (url == null && !reqPath.startsWith("/")) {
        url = clazz.getResource("/");
    }/*from   w ww  .  j  a  v a2s .  com*/
    if (url == null && (reqPath.length() > 1) && reqPath.startsWith("/")) {
        url = clazz.getResource(reqPath.substring(1));
    }
    return url;
}