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:org.hdiv.web.servlet.support.GrailsHdivRequestDataValueProcessor.java

/**
 * Process the url for a link./*  w w  w.j  a v  a  2 s  .  co m*/
 * 
 * @param request
 *            request object
 * @param url
 *            link url
 * @return processed url
 */
public String processUrl(HttpServletRequest request, String url) {
    String urlToProcess = url;
    Boolean modified = false;
    String contextPath = request.getContextPath();
    if (url.indexOf("/") == 0 && contextPath.length() > 1 && url.indexOf(contextPath) != 0) {
        urlToProcess = contextPath + url;
        modified = true;
    }
    String processedUrl = super.processUrl(request, urlToProcess);
    if (modified) {
        return processedUrl.substring(contextPath.length());
    }
    return processedUrl;
}

From source file:com.netstorm.localization.MyLocaleResolver.java

public LocalesServiceBean createLocaleBean(HttpServletRequest request) {
    String sub_path;//from  w w w  . j  a va 2s.co  m
    String contextPath = request.getContextPath();
    String uri = request.getRequestURI();
    int index1 = 1 + contextPath.length();
    int index2 = uri.indexOf("/", index1);

    if (index2 > index1) {
        String locale_name = uri.substring(index1, index2);
        Boolean active = (Boolean) locale_service.getSinglePropertyU("active", "name", locale_name);
        sub_path = uri.substring(index2);

        if (active != null && (active || sub_path.startsWith(all_locales_prefix))) {
            return new LocalesServiceBean(locale_service, getDefaultLocale(), new java.util.Locale(locale_name),
                    sub_path, !sub_path.startsWith(all_locales_prefix));
        }
    }

    Locale locale = getDefaultLocale();
    if (locale == null) {
        locale = Locale.getDefault();
    }
    sub_path = uri.substring(contextPath.length());
    return new LocalesServiceBean(locale_service, getDefaultLocale(), locale, sub_path,
            !sub_path.startsWith(all_locales_prefix));
}

From source file:org.jtwig.functions.SpringFunctions.java

@JtwigFunction(name = "path")
public String path(HttpServletRequest request, @Parameter String input) {
    return new UrlPath().append(request.getContextPath()).append(input).toString();
}

From source file:org.slc.sli.dashboard.util.DashboardExceptionResolver.java

protected void setContextPath(ModelMap model, HttpServletRequest request) {
    model.addAttribute(Constants.CONTEXT_ROOT_PATH, request.getContextPath());
    model.addAttribute(Constants.CONTEXT_PREVIOUS_PATH, "javascript:history.go(-1)");
}

From source file:com.reever.humilheme.web.CookieController.java

public Cookie createCookie(HttpServletRequest request, HttpServletResponse response, String conteudo) {
    String path = StringUtils.isEmpty(request.getContextPath()) ? "/" : request.getContextPath();
    try {//from   ww w .jav a2  s  .  c  om
        conteudo = URLEncoder.encode(conteudo, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        _logger.error("Erro no encode do cookie", e);
    }
    Cookie cookie = new Cookie(nomeCookie, conteudo);
    cookie.setMaxAge(expiry);
    cookie.setPath(path);
    cookie.setVersion(1);
    response.addCookie(cookie);
    return cookie;
}

From source file:org.apache.cxf.fediz.spring.web.FederationLogoutFilter.java

@Override
protected boolean requiresLogout(HttpServletRequest request, HttpServletResponse response) {
    if (this.logoutUrl == null) {
        String contextName = request.getContextPath();
        if (contextName == null || contextName.isEmpty()) {
            contextName = "/";
        }/*from  w w  w.  ja  v  a  2  s .  c o m*/
        this.logoutUrl = federationConfig.getFedizContext(contextName).getLogoutURL();
    }
    if (this.logoutUrl != null && !this.logoutUrl.isEmpty()) {
        super.setFilterProcessesUrl(this.logoutUrl);
        return super.requiresLogout(request, response);
    }
    return false;
}

From source file:org.perconsys.controllers.AuthController.java

@RequestMapping({ "", "/info", "/default" })
public String defaultPage(@CookieValue String authKey, HttpServletRequest request, ModelMap model) {
    // check authKey
    model.addAttribute("basePath", request.getContextPath() + basePath);
    return "auth/default";
}

From source file:controller.FeedbackControllerManager.java

@RequestMapping(value = "/process", method = RequestMethod.POST)
public String processFeedback(HttpServletRequest req, ModelMap mm, @ModelAttribute Feedback feed) {
    try {/*  w  ww .  j a  va2 s.c  o  m*/
        String contextPath = req.getContextPath();
        feed.setStatus(Byte.valueOf("1"));
        mm.put("check", feedModel.addOrUpdate(feed));
        mm.put("alert", "Feedback Updated");
        mm.put("link", contextPath + "/admin/feedbackManager.html");

    } catch (Exception ex) {
        ex.printStackTrace();
        mm.put("err", ex.getMessage());
    }
    return "processFeedback";
}

From source file:com.jaspersoft.jasperserver.war.util.RequestParameterAuthenticationFilter.java

protected String getFullFailureUrl(HttpServletRequest request) {
    return request.getContextPath() + authenticationFailureUrl;
}

From source file:es.osoco.grails.plugins.otp.access.InterceptUrlMapMultipleVoterFilterInvocationDefinition.java

@Override
protected String determineUrl(final FilterInvocation filterInvocation) {
    HttpServletRequest request = filterInvocation.getHttpRequest();
    String requestUrl = request.getRequestURI().substring(request.getContextPath().length());
    return lowercaseAndStripQuerystring(requestUrl);
}