0

I have a j2ee application with a web.xml having a default servlet to handle all requests.

<servlet>
    <servlet-name>controller</servlet-name>
    <servlet-class>gr.comp.pjx.controller.FrontController</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

The strange behavior is when the application's context is loaded. So, when netbeans loads http://localhost:8080/my_application/ I see that my servlet class(i.e. gr.comp.pjx.controller.FrontController) does not catch the request. This was not the case when having Tomcat 6. In addition to this, when I manually enter a page url e.g. http://localhost:8080/my_application/login.jsp the same servlet class catches normally the request as it was expected.

Does anyone have a similar issue?

jkonst
  • 433
  • 6
  • 20
  • Does that xml belongs to tomcat 8 ? – hurricane May 22 '15 at 13:47
  • No this belongs to my application. – jkonst May 22 '15 at 13:51
  • 1
    See http://stackoverflow.com/questions/4140448/difference-between-and-in-servlet-mapping-url-pattern – Pino May 22 '15 at 13:56
  • I think you should configure your context.xml and server.xml with your application. – hurricane May 22 '15 at 13:57
  • context.xml is correctly set server.xml is within tomcat and it has nothing specific to do with my application – jkonst May 22 '15 at 14:07
  • If you have a `path` attribute in any `context.xml`, then you have a horribly broken configuration. Exactly which `context.xml` contains the `path` attribute? – Christopher Schultz May 24 '15 at 15:55
  • what do you mean "broken configuration"? I've got context.xml within META-INF directory of my application. Is something wrong with the path attribute? – jkonst May 25 '15 at 07:23
  • Beyond this, within \tomcat\conf\Catalina\localhost\ there is a my_application.xml that contains the full path of the application i.e. However, when I try to access http://localhost:8080/my_application I get a 404 error – jkonst May 25 '15 at 10:10

1 Answers1

0

I resolved this issue by adding a servlet mapping using the empty string, so that the application's context root(i.e. http://localhost/my_application) can be served by gr.comp.pjx.controller.FrontController

<servlet>
    <servlet-name>controller1</servlet-name>
    <servlet-class>gr.eworx.pjx.controller.FrontController</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>controller1</servlet-name>
    <url-pattern></url-pattern>
</servlet-mapping>

So, this servlet mapping was added just before the existing servlet mapping with the default servlet. Now every request can be served by gr.eworx.pjx.controller.FrontController However, the question that is not answered is why the '/' url pattern cannot be used in order to serve the application's context root in Tomcat > 6

jkonst
  • 433
  • 6
  • 20
  • you ever figure this out? My problem is very similar, but on my case I have multiple servlets with url-pattern like "/fortive3/tsmService". Also, in my web.xml, there already is a "default" with url-pattern = '/', similar to yours, so I guess in my case your fix does not work?? – Tony B May 19 '19 at 22:03