01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork;
06:
07: import javax.servlet.http.HttpServletRequest;
08:
09: /**
10: * Request handling utility class.
11: *
12: * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
13: */
14: public class RequestUtils {
15:
16: /**
17: * Retrieves the current request servlet path.
18: * Deals with differences between servlet specs (2.2 vs 2.3+)
19: *
20: * @param request the request
21: * @return the servlet path
22: */
23: public static String getServletPath(HttpServletRequest request) {
24: String servletPath = request.getServletPath();
25:
26: if (null != servletPath && !"".equals(servletPath)) {
27: return servletPath;
28: }
29:
30: String requestUri = request.getRequestURI();
31: int startIndex = request.getContextPath().equals("") ? 0
32: : request.getContextPath().length();
33: int endIndex = request.getPathInfo() == null ? requestUri
34: .length() : requestUri.lastIndexOf(request
35: .getPathInfo());
36:
37: if (startIndex > endIndex) { // this should not happen
38: endIndex = startIndex;
39: }
40:
41: return requestUri.substring(startIndex, endIndex);
42: }
43:
44: }
|