Example usage for javax.servlet.http HttpServletRequest getServletPath

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

Introduction

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

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:com.tc.utils.XSPUtils.java

public static String getURL() {

    HttpServletRequest req = XSPUtils.getRequest();
    String scheme = req.getScheme(); // http
    String serverName = req.getServerName(); // hostname.com
    int serverPort = req.getServerPort(); // 80
    String contextPath = req.getContextPath(); // /mywebapp
    String servletPath = req.getServletPath(); // /servlet/MyServlet
    String pathInfo = req.getPathInfo(); // /a/b;c=123
    String queryString = req.getQueryString(); // d=789

    // Reconstruct original requesting URL
    StringBuffer url = new StringBuffer();
    url.append(scheme).append("://").append(serverName);

    if ((serverPort != 80) && (serverPort != 443)) {
        url.append(":").append(serverPort);
    }/*from  w w w .j  av a2  s.  com*/

    url.append(contextPath).append(servletPath);

    if (pathInfo != null) {
        url.append(pathInfo);
    }
    if (queryString != null) {
        url.append("?").append(queryString);
    }
    return url.toString();
}

From source file:com.feilong.servlet.http.RequestUtil.java

/**
 * Return the servlet path for the given request, detecting an include request URL if called within a RequestDispatcher include.
 * //w  ww. j a v  a  2 s.  c  o  m
 * @param request
 *            current HTTP request
 * @return the servlet path
 */
public static String getOriginatingServletPath(HttpServletRequest request) {
    String servletPath = getAttribute(request, RequestAttributes.FORWARD_SERVLET_PATH);
    return isNotNullOrEmpty(servletPath) ? servletPath : request.getServletPath();
}

From source file:net.cloudfree.apps.shop.internal.app.JsonListingServlet.java

private static StringBuilder getBaseUrl(final HttpServletRequest req) {
    final StringBuilder builder = new StringBuilder(50);
    builder.append(req.getScheme());//  ww  w  .ja  v a  2  s  . co  m
    builder.append("://");
    builder.append(req.getServerName());
    if ((req.getScheme().equals("http") && (req.getServerPort() != 80))
            || (req.getScheme().equals("https") && (req.getServerPort() != 443))) {
        builder.append(":");
        builder.append(req.getServerPort());
    }
    builder.append(req.getContextPath());
    builder.append(req.getServletPath());
    builder.append("/");
    return builder;
}

From source file:cn.bc.web.util.WebUtils.java

/**
 * ???
 * //from   w w w.j av  a  2 s  .  co m
 * <pre>
 * http://www.demo.com/demo/test.htm  -->  /demo/test.htm</span>
 * </pre>
 * 
 * @param request
 * @return ?/demo/test.htm
 */
public static String getResourcePath(HttpServletRequest request) {
    // Adapted from VelocityViewServlet.handleRequest() method:

    // If we get here from RequestDispatcher.include(), getServletPath()
    // will return the original (wrong) URI requested. The following
    // special attribute holds the correct path. See section 8.3 of the
    // Servlet 2.3 specification.

    String path = (String) request.getAttribute("javax.servlet.include.servlet_path");

    // Also take into account the PathInfo stated on
    // SRV.4.4 Request Path Elements.
    String info = (String) request.getAttribute("javax.servlet.include.path_info");

    if (path == null) {
        path = request.getServletPath();
        info = request.getPathInfo();
    }

    if (info != null) {
        path += info;
    }

    return path;
}

From source file:org.italiangrid.storm.webdav.authz.util.CustomMethodAntPathRequestMatcher.java

private String getRequestPath(HttpServletRequest request) {

    String url = request.getServletPath();

    if (request.getPathInfo() != null) {
        url += request.getPathInfo();//from   w  ww.  j a va2  s  . c om
    }

    return url;
}

From source file:org.jdal.auth.AuthFilter.java

protected boolean isLoginPage(HttpServletRequest request) {
    return ("/login.jsp".equals(request.getServletPath()) || "/login.do".equals(request.getServletPath()));
}

From source file:com.cloudfoundry.samples.spring.user.UserInterceptor.java

private boolean requestForSignIn(HttpServletRequest request) {
    return request.getServletPath().startsWith("/signin");
}

From source file:net.zouabimourad.springsocialjira.auth.UserInterceptor.java

private boolean requestForResources(HttpServletRequest request) {
    return request.getServletPath().startsWith("/resources");
}

From source file:com.boundlessgeo.geoserver.AppDispatcher.java

@Override
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
    String servletPath = request.getServletPath();
    if (servletPath != null && servletPath.startsWith(API_PATH)) {
        //JD: Hack to deal with the GeoServer "advanced dispatch", the point here is that we want to expose
        // the rest api directly "/api"
        request = new HttpServletRequestWrapper(request) {
            @Override/*w w w . ja  v a2  s .c  o  m*/
            public String getRequestURI() {
                return super.getRequestURI().replace(API_PATH, API_PATH + API_PATH);
            }
        };
    }

    return super.getHandler(request);
}

From source file:opentipbot.web.security.UserInterceptor.java

private boolean requestForNotProtected(HttpServletRequest request) {
    return request.getServletPath().startsWith("/signin")
            || request.getServletPath().startsWith("/documentation")
            || request.getServletPath().startsWith("/about");
}