Hi all,

I am using the latest stable version of Tomcat Embedded. I have a question regarding how redirect works for a servlet.

My servlet mapping name is "RexaRetrieval". The basic problem I was having is that when I send a POST request, the HttpServletRequest always says it is a GET.

If the URL I put in is:
   "http://localhost:8081/RexaRetrieval"
This causes a redirect to a GET request.

If the URL is:
  "http://localhost:8081/RexaRetrieval/"
This works. The only difference is the trailing '/' character.

Resin does not have this problem. When I deploy the same war, both POST requests work.

The relevant source code is in org.apache.tomcat.util.http.mapper.Mapper line 641:
   1         boolean noServletPath = false;
   2 
   3         int length = context.name.length();
   4         if (length != (pathEnd - pathOffset)) {
   5             servletPath = pathOffset + length;
   6         } else {
   7             noServletPath = true;
   8             path.append('/');
   9             pathOffset = path.getOffset();
  10             pathEnd = path.getEnd();
  11             servletPath = pathOffset+length;
  12         }

Note the !=. This means if a trailing forward slash is missing, "noServletPath" is true.

The in Mapper line 688:
   1         if(mappingData.wrapper == null && noServletPath) {
   2             // The path is empty, redirect to "/"
   3             mappingData.redirectPath.setChars
   4                 (path.getBuffer(), pathOffset, pathEnd);
   5             path.setEnd(pathEnd - 1);
   6             return;
   7         }

Another related question: how is this redirect suposed to work? The original method was POST. Does it always redirect to GET when there is a servlet path? What if I were to post to a URL like "http://localhost:8081/RexaRetrieval/foo". I am guessing the correct action here would be that this redirects to a GET because posting to such a URL doesn't make sense.

Thanks,
Rich

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to