Revision: 977
http://stripes.svn.sourceforge.net/stripes/?rev=977&view=rev
Author: bengunter
Date: 2008-10-17 03:33:31 +0000 (Fri, 17 Oct 2008)
Log Message:
-----------
Applied fix for STS-575 from trunk (revision 975).
Revision Links:
--------------
http://stripes.svn.sourceforge.net/stripes/?rev=975&view=rev
Added Paths:
-----------
branches/1.5.x/stripes/src/net/sourceforge/stripes/util/HttpUtil.java
Added: branches/1.5.x/stripes/src/net/sourceforge/stripes/util/HttpUtil.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/util/HttpUtil.java
(rev 0)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/util/HttpUtil.java
2008-10-17 03:33:31 UTC (rev 977)
@@ -0,0 +1,67 @@
+/* Copyright 2008 Ben Gunter
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sourceforge.stripes.util;
+
+import javax.servlet.http.HttpServletRequest;
+
+import net.sourceforge.stripes.controller.StripesConstants;
+
+/**
+ * Provides helper methods for working with HTTP requests and responses.
+ *
+ * @author Ben Gunter
+ * @since Stripes 1.5.1
+ */
+public class HttpUtil {
+ /**
+ * <p>
+ * Get the path from the given request. This method is different from
+ * [EMAIL PROTECTED] HttpServletRequest#getRequestURI()} in that it
concatenates and returns the servlet
+ * path plus the path info from the request. These are usually the same,
but in some cases they
+ * are not.
+ * </p>
+ * <p>
+ * One case where they are known to differ is when a request for a
directory is forwarded by the
+ * servlet container to a welcome file. In that case, [EMAIL PROTECTED]
HttpServletRequest#getRequestURI()}
+ * returns the path that was actually requested (e.g., [EMAIL PROTECTED]
"/"}), whereas the servlet path
+ * plus path info is the path to the welcome file (e.g. [EMAIL PROTECTED]
"/index.jsp"}).
+ * </p>
+ */
+ public static String getRequestedPath(HttpServletRequest request) {
+ String servletPath, pathInfo;
+
+ // Check to see if the request is processing an include, and pull the
path
+ // information from the appropriate source.
+ servletPath = (String)
request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH);
+ if (servletPath != null) {
+ pathInfo = (String)
request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH_INFO);
+ }
+ else {
+ servletPath = request.getServletPath();
+ pathInfo = request.getPathInfo();
+ }
+
+ if (servletPath == null)
+ return pathInfo == null ? "" : pathInfo;
+ else if (pathInfo == null)
+ return servletPath;
+ else
+ return servletPath + pathInfo;
+ }
+
+ /** No instances */
+ private HttpUtil() {
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development