On 06/06/2019 09:27, Mark Thomas wrote:
> On 06/06/2019 08:31, Rob Nikander wrote:
>> Hi,
>>
>> I would like requests to a webapp to have paths that look like this:
>>
>>     http://server/myapp <http://server/myapp>   not:  http://server/myapp/ 
>> <http://server/myapp/>
>>
>> But for some reason, Tomcat keeps redirecting the 1st to the 2nd. I’m aware 
>> of the attribute `mapperContextRootRedirectEnabled` (on the Context), but 
>> setting that to “false” is not helping.  My web.xml looks like:
>>
>>     <servlet-mapping>
>>         <servlet-name>MyServlet</servlet-name>
>>         <url-pattern></url-pattern>
>>         <url-pattern>/other</url-pattern>
>>         …
>>
>> What is going on? How do I stop the redirects?
> 
> Why do you want to do this? What problem are you trying to solve?
> 
> I'm not sure you what you are asking is possible although I'll need to
> dig through the mapping code to be certain.
This is going to come down to what the Servlet spec says.

<spec-quote section="12.2">
The empty string ("") is a special URL pattern that exactly maps
to the application's context root, i.e., requests of the form
http://host:port/<context-root>/
</spec-quote>

<spec-quote section="10.10">
A request URI of /foo will be redirected to a URI of /foo/
</spec-quote>

Section 12.2 states that an application's context root includes the
trailing slash.

Section 10.10 states that requests for directories without a trailing
slash will be redirected.

Hence you see a redirect. Either from the Mapper or from the Default
Servlet.

I did look at the possibility of mapping http://host:port/<context-root>
directly to a Servlet mapped to "". I wondered about security
constraints but RealmBase looks like it would handle this case correctly.

What makes me think this is the wrong thing to do is the next part of
section 12.2.

<spec-quote section="12.2">
In this case the path info is ’/’ and the servlet path
and context path is empty string (““).
</spec-quote>

Given that "RequestURI = ContextPath + ServletPath + PathInfo", the
statement that the path info in this case is "/" makes me think that the
current Tomcat behaviour is correct.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to