FileDocCategorySizeDatePackage
RequestUtils.javaAPI DocExample1972Mon Jul 23 13:26:56 BST 2007org.apache.struts2

RequestUtils

public class RequestUtils extends Object
Request handling utility class.

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringgetServletPath(javax.servlet.http.HttpServletRequest request)
Retrieves the current request servlet path. Deals with differences between servlet specs (2.2 vs 2.3+)

param
request the request
return
the servlet path

        String servletPath = request.getServletPath();

        if (null != servletPath && !"".equals(servletPath)) {
            return servletPath;
        }

        String requestUri = request.getRequestURI();
        int startIndex = request.getContextPath().equals("") ? 0 : request.getContextPath().length();
        int endIndex = request.getPathInfo() == null ? requestUri.length() : requestUri.lastIndexOf(request.getPathInfo());

        if (startIndex > endIndex) { // this should not happen
            endIndex = startIndex;
        }

        return requestUri.substring(startIndex, endIndex);