You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by GreggCarrier <gr...@gmail.com> on 2010/03/06 01:56:15 UTC
Servlet mapping, welcome file and trailing slashes
I'm having a frustrating problem and I can't find the right configuration for
what I want. Hoping someone can offer some insight.
Desired behavior: I want all requests to my webapp to be handled by one
servlet except requests for index.jsp or the root of the webapp. I do not
want trailing slashes to be required in order to load URLs.
The setups I have tried and the results:
1 - <servlet-mapping>
<servlet-name>Jersey Spring Web Application</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
In this case, the index.jsp loads fine at /mywebapp/. The servlet handles
all other requests appropriately EXCEPT it requires a trailing slash at the
end of all URLs. Eg, /mywebapp/foo/ loads but /mywebapp/foo does not. This
setup would be perfect except for the trailing slash requirement. I want it
to load with or without the trailing slash.
2 - <servlet-mapping>
<servlet-name>Jersey Spring Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
With this setup the servlet handles requests with and without the trailing
slash (correctly). The index.jsp will not load at /mywebapp/ or
/mywebapp/index.jsp.
Any ideas? Thanks very much!
Gregg
--
View this message in context: http://old.nabble.com/Servlet-mapping%2C-welcome-file-and-trailing-slashes-tp27801086p27801086.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Servlet mapping, welcome file and trailing slashes
Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/3/6 Pid <pi...@pidster.com>:
> Maybe one of the devs can confirm whether it's the DefaultServlet which
> handles the redirect/forward/whatever from /dir to the trailing slash
> variant /dir/? (I couldn't work it out from a quick look in SVN)
>
I think that is o.a.tomcat.util.http.mapper.Mapper#internalMapWrapper(..)
See [The path is empty, redirect to "/"] comment there.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Servlet mapping, welcome file and trailing slashes
Posted by Pid <pi...@pidster.com>.
On 06/03/2010 00:56, GreggCarrier wrote:
>
> I'm having a frustrating problem and I can't find the right configuration for
> what I want. Hoping someone can offer some insight.
>
> Desired behavior: I want all requests to my webapp to be handled by one
> servlet except requests for index.jsp or the root of the webapp. I do not
> want trailing slashes to be required in order to load URLs.
>
> The setups I have tried and the results:
>
> 1 -<servlet-mapping>
> <servlet-name>Jersey Spring Web Application</servlet-name>
> <url-pattern>/</url-pattern>
> </servlet-mapping>
>
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
>
> In this case, the index.jsp loads fine at /mywebapp/. The servlet handles
> all other requests appropriately EXCEPT it requires a trailing slash at the
> end of all URLs. Eg, /mywebapp/foo/ loads but /mywebapp/foo does not. This
> setup would be perfect except for the trailing slash requirement. I want it
> to load with or without the trailing slash.
>
> 2 -<servlet-mapping>
> <servlet-name>Jersey Spring Web Application</servlet-name>
> <url-pattern>/*</url-pattern>
> </servlet-mapping>
>
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
>
> With this setup the servlet handles requests with and without the trailing
> slash (correctly). The index.jsp will not load at /mywebapp/ or
> /mywebapp/index.jsp.
>
> Any ideas? Thanks very much!
Maybe one of the devs can confirm whether it's the DefaultServlet which
handles the redirect/forward/whatever from /dir to the trailing slash
variant /dir/? (I couldn't work it out from a quick look in SVN)
In 1) you are replacing the DefaultServlet, which may have other
consequences for your application.
In 2) the wildcard overrides the request for the welcome-file.
A Servlet Filter as previously suggested, would be my solution.
p
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Servlet mapping, welcome file and trailing slashes
Posted by Donn Aiken <do...@gmail.com>.
Gregg -
Any chance you could do this in two steps?
Could you implement a filter on the url pattern /* . If the request
uri is for something in the root, chain it through. If it is not,
forward it to the required servlet?
Just a thought.
DJ
On 3/5/10, GreggCarrier <gr...@gmail.com> wrote:
>
> I'm having a frustrating problem and I can't find the right configuration
> for
> what I want. Hoping someone can offer some insight.
>
> Desired behavior: I want all requests to my webapp to be handled by one
> servlet except requests for index.jsp or the root of the webapp. I do not
> want trailing slashes to be required in order to load URLs.
>
> The setups I have tried and the results:
>
> 1 - <servlet-mapping>
> <servlet-name>Jersey Spring Web Application</servlet-name>
> <url-pattern>/</url-pattern>
> </servlet-mapping>
>
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
>
> In this case, the index.jsp loads fine at /mywebapp/. The servlet handles
> all other requests appropriately EXCEPT it requires a trailing slash at the
> end of all URLs. Eg, /mywebapp/foo/ loads but /mywebapp/foo does not. This
> setup would be perfect except for the trailing slash requirement. I want it
> to load with or without the trailing slash.
>
> 2 - <servlet-mapping>
> <servlet-name>Jersey Spring Web Application</servlet-name>
> <url-pattern>/*</url-pattern>
> </servlet-mapping>
>
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
>
> With this setup the servlet handles requests with and without the trailing
> slash (correctly). The index.jsp will not load at /mywebapp/ or
> /mywebapp/index.jsp.
>
> Any ideas? Thanks very much!
>
> Gregg
> --
> View this message in context:
> http://old.nabble.com/Servlet-mapping%2C-welcome-file-and-trailing-slashes-tp27801086p27801086.html
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
--
Sent from my mobile device
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Servlet mapping, welcome file and trailing slashes
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: GreggCarrier [mailto:greggcarrier@gmail.com]
> Subject: Servlet mapping, welcome file and trailing slashes
>
> 2 - <servlet-mapping>
> <servlet-name>Jersey Spring Web Application</servlet-name>
> <url-pattern>/*</url-pattern>
> </servlet-mapping>
>
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
Not sure if this will work, but try adding the following to the above:
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
If it works at all, it will only do so for an index.jsp located in the base directory of the webapp, not further down in the structure.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Servlet mapping, welcome file and trailing slashes
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Gregg,
On 3/5/2010 7:56 PM, GreggCarrier wrote:
> I'm having a frustrating problem and I can't find the right configuration for
> what I want. Hoping someone can offer some insight.
>
> Desired behavior: I want all requests to my webapp to be handled by one
> servlet except requests for index.jsp or the root of the webapp. I do not
> want trailing slashes to be required in order to load URLs.
I can hardly find any documentation for SpringServlet in the Jersey
project. :( It's likely that the SpringServlet doesn't respect the
<welcome-file> entries in web.xml because accessing that information is
not part of the servlet API. That isn't to say that the developers
didn't parse web.xml themselves, but I doubt they did that: they would
expect you to map only the appropriate URI patterns to SpringServlet.
The examples I see are always of the form:
<url-pattern>/something/*</url-pattern>
...which suggests to me that the REST portion of your webapp might be
expected to be segregated from the rest of the webapp by a particular
URL prefix. I think that's rather a good idea because then you know that
all requests to /something/* will always be handled as REST calls and
those outside of that pattern will be non-REST requests.
Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkuVErUACgkQ9CaO5/Lv0PBh0ACgpnoHFWxhAwCg+Utf7z1dTFkD
qTwAn1s5QJai/K34ERDPxnoQi/V9e/sY
=cMa3
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org