You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Zheng Yang <zh...@gmail.com> on 2013/05/12 14:40:52 UTC

Tomcat 7 Application Context root url mapping broken after reload.

Hi list,

I learned that @WebServlet("") is for mapping the application context root.
e.g. http://localhost:8080/myapp/
Unfortunately doesn't work after a context reload.
This problem can be easily reproduced:

1.Create a HelloWorld application with a single servlet, say the servlet is
called RootServlet.java
2.Map RootServlet to context root using @WebServlet("") annotation
3.If you deploy it on a local tomcat server, it will work.
http://localhost:8080/HelloWorld/ will give whatever you print in
RootServlet
4.But if you reload the app (say using the manager app),
http://localhost:8080/HelloWorld/ will give 404 error. RootServlet is never
called this time.

Environment: Windows 8, Java 7, Tomcat 7.0.40

Is this the intended behavior or a bug actually?
-- 
------
Regards,
Zheng Yang

Re: Tomcat 7 Application Context root url mapping broken after reload.

Posted by Zheng Yang <zh...@gmail.com>.
Thanks for the info.

If it happens as you describe it, then it should be a bug. Please file
> an issue in Bugzilla.
> http://tomcat.apache.org/bugreport.html#How_to_write_a_bug_report
>
>
I've filed a bug here:
https://issues.apache.org/bugzilla/show_bug.cgi?id=54955


> Can you attach to your report a simple web application, with source
> code, that reproduces the issue?
>
> Two questions:
> a) Is it specific to the context root (empty string) mapping?
>

Yes, only the empty string mapping will broke while the others are OK.


> b) Is it specific to annotations? (Does it work if you specify the
> mapping in web.xml)?
>
> Nope, both annotations and DD fail.


> BTW, support for such mappings was added to Tomcat 7 rather late (in
> 7.0.28 - bug 53356 ).  Apparently they are no so widely used.
>
>
> If this is the case, what is considered as best practice when I need a
servlet to handle context root?
The function I'm trying to achieve is a 2-face context root: For logged-in
users, show home.jsp with params passed from root servlet. For users not
logged-in, show index.jsp.


-- 
------
Regards,
Zheng Yang

Re: Tomcat 7 Application Context root url mapping broken after reload.

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/5/12 Zheng Yang <zh...@gmail.com>:
> Hi list,
>
> I learned that @WebServlet("") is for mapping the application context root.
> e.g. http://localhost:8080/myapp/
> Unfortunately doesn't work after a context reload.
> This problem can be easily reproduced:
>
> 1.Create a HelloWorld application with a single servlet, say the servlet is
> called RootServlet.java
> 2.Map RootServlet to context root using @WebServlet("") annotation
> 3.If you deploy it on a local tomcat server, it will work.
> http://localhost:8080/HelloWorld/ will give whatever you print in
> RootServlet
> 4.But if you reload the app (say using the manager app),
> http://localhost:8080/HelloWorld/ will give 404 error. RootServlet is never
> called this time.
>
> Environment: Windows 8, Java 7, Tomcat 7.0.40
>
> Is this the intended behavior or a bug actually?
>

If it happens as you describe it, then it should be a bug. Please file
an issue in Bugzilla.
http://tomcat.apache.org/bugreport.html#How_to_write_a_bug_report

Can you attach to your report a simple web application, with source
code, that reproduces the issue?

Two questions:
a) Is it specific to the context root (empty string) mapping?
b) Is it specific to annotations? (Does it work if you specify the
mapping in web.xml)?

BTW, support for such mappings was added to Tomcat 7 rather late (in
7.0.28 - bug 53356 ).  Apparently they are no so widely used.

Best regards,
Konstantin Kolinko

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