13

Recently I upgraded my tomcat server from 6.x version to the most recent 7.x version.

I came up with little trouble, hoping to get help.

I have an application calls MyApp

On tomcat6, when I went to http://www.example.com/MyApp/page/ I normally would get the wanted result.

Now, on tomcat7, visiting the same exact url (with the trailing slash) I'm getting the error: "Resource is not avaliable", as the tomcat thinks that /MyApp/page/ is a whole webapp name instead of being request names page under the MyApp webapp.

I need the slash at the end on my url because otherwise I'm getting the error: "HTTP Status 405 - Request method 'GET' not supported" which is OK because I really did not permit the GET method to the "page" request.

If someone knows how to tell tomcat that trailing slash after path of existing webapp should not suppose to redirect it to new webapp calls the whole "string" and just process the request like on tomcat6, it would be great!

  • Is there a default servlet in the `web.xml` that is mapped to `/*`? Otherwise tomcat uses a welcome-file-list. Normally only the first path segment is interpredet as a context root. So not finding your webapp does not seem to be the problem. – mana Oct 24 '12 at 15:18
  • the first path segment is a context root and really works, it finds it, but the follows paths instead of being part of the first path, the tomcat search for webapp with all the path.. I don't have anything that is configure that is non-default.. –  Oct 24 '12 at 15:43
  • I don't really get what you are saying. Sorry. If you have a webapp configured with the name `MyApp` then tomcat will use this web application context using the remaining path `page/`. If not, it will look for the `ROOT` context, using the full path for a lookup. – mana Oct 24 '12 at 16:52
  • I have a webapp calls MyApp and http://www.example.com/MyApp is working, but when visiting http://www.example.com/MyApp/foo/ instead of looking for foo content inside MyApp, it searches for a webapp calls "MyApp/foo/" and not looking for the content under MyApp calls foo .. –  Oct 25 '12 at 12:07
  • 2
    Try this: http://stackoverflow.com/q/11055608/1031900 –  Oct 25 '12 at 13:45

3 Answers3

1

Ancient question, but since I have recently battled with the terminating slash in Tomcat 8, I know that problems with the slash continues to plague the Tomcat user world. :-)

What you might be running into is changes in the way that Tomcat handles redirects when loading the root context. Check out bug 58660 and read some of the developer discussion there. You may need to turn off the default mapper by modifying the mapperContextRootRedirectEnabled attribute of the Context element in conf/context.xml.

Peter
  • 121
  • 1
0

Check your welcome-file-list .. what follows is speculation ...

I believe the essence of issue is when Tomcat is presented with a / - It has a few options - Iterate over the welcome file list - On nothing being there -- show directory listing (if enabled)

Here's where the fun begins ... Lots of folks want to use *.do for things like struts. So they want index.do to be the home page. Or also common is index.jsp where *.jsp is mapped to the JspServlet.

Here's where things get fun. So lets say your welcome files is index.jsp, index.do.

What Tomcat (IIRC) is doing is first iterating over the welcome file list looking for resources of that name.

Then it will do a second pass looking for mappings that match. So if index.jsp is specified in the welcome list and *.jsp is mapped. Then tomcat will try to forward to index.jsp and you'll get a 404.

So I'm going to guess you have a servlet mapping and welcome file overlapping. And the behavior of that servlet doesn't support GET. (Hence the 405)

Tim Funk
  • 436
  • 2
  • 4
0

If your project is using dynamic web module of v2.2, you need to explicitly create atleast one file (can be empty html file) present in web.xml(eg:index.html) in your WebContent.

Snehal
  • 1