tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Parker <mp...@voyanttech.com>
Subject Re: [PATCH] forward instead of redirect for welcome files
Date Tue, 07 Jan 2003 15:59:02 GMT
On Tue, 2003-01-07 at 04:40, Remy Maucherat wrote:
> I'll -1 this patch unless the new behavior is made optional (and default 
> to the current behavior).
> 
> Remy

Okay, it's now an init param which defaults to false. Following are
DefaultServlet.java and web.xml patches.


--- DefaultServlet.java.orig	2003-01-07 08:41:16.000000000 -0700
+++ DefaultServlet.java	2003-01-07 08:42:33.000000000 -0700
@@ -169,6 +169,10 @@
      */
     protected String welcomes[] = new String[0];
 
+    /**
+     * Should we redirect or forward for welcome files?
+     */
+    protected boolean forwardWelcomeFiles = false;
 
     /**
      * MD5 message digest provider.
@@ -294,6 +298,13 @@
         } catch (Throwable t) {
             ;
         }
+        try {
+            value =
getServletConfig().getInitParameter("forwardWelcomeFiles");
+            if (value != null)
+                forwardWelcomeFiles = (new
Boolean(value)).booleanValue();
+        } catch (Throwable t) {
+            ;
+        }
 
         // Sanity check on the specified buffer sizes
         if (input < 256)
@@ -957,11 +968,16 @@
             if (welcomeFileInfo != null) {
                 String redirectPath = welcomeFileInfo.path;
                 String contextPath = request.getContextPath();
-                if ((contextPath != null) &&
(!contextPath.equals("/"))) {
+                if ((contextPath != null) && (!contextPath.equals("/"))
&& (!forwardWelcomeFiles)) {
                     redirectPath = contextPath + redirectPath;
                 }
                 redirectPath = appendParameters(request, redirectPath);
-                response.sendRedirect(redirectPath);
+                if (forwardWelcomeFiles) {
+                  
request.getRequestDispatcher(redirectPath).forward(request, response);
+                }
+                else {
+                   response.sendRedirect(redirectPath);
+                }
                 return;
             }

--- web.xml.orig	2003-01-07 08:58:09.000000000 -0700
+++ web.xml	2003-01-07 08:50:13.000000000 -0700
@@ -39,6 +39,9 @@
   <!--   readonly            Is this context "read only", so
HTTP           -->
   <!--                       commands like PUT and DELETE
are               -->
   <!--                       rejected? 
[true]                              -->
+ 
<!--                                                                      -->
+  <!--   forwardWelcomeFiles Should welcome files be forwarded
instead      -->
+  <!--                       of being redirected?
[false]                   -->
 
     <servlet>
         <servlet-name>default</servlet-name>







--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message