Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Working with Servlet Annotations  RSS feed

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is Servlet with annotation @WebServlet

And Below is the filter with annotation @WebFilter


And here is my web.xml

First question:
So servlet com.emind.MyServlet will be called for url patterns /Ask and /processForm and /callServlet and it works.
But Servlet init parameters are null in case of /Ask .
So when I try to call my servlet using url pattern /callServlet and /processForm I can see those to init parameters.
So it means that those init params that we have declared using annotation is only for those url patterns that we have specified in annotation.

Second question:
Filter Is called for only url patterns /processForm and /callServlet not for url /Ask

Third question:
When we use annotations what that annotation means is not translated (expanded) into web.xml
I was thinking that container will change your web.xml to

 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahtab Alam wrote:
When we use annotations what that annotation means is not translated (expanded) into web.xml
I was thinking that container will change your web.xml to


No (er... yes to the first sentence). The annotations are interpreted at runtime (which is startup for a container). The XML will not be changed and the existing will be treated independently. You shouldn't mix the different methods for configuring an application. Use either XML or annotations.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What about first two questions
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it means that those init params that we have declared using annotation is only for those url patterns that we have specified in annotation.

That's how I would interpret it.

Filter Is called for only url patterns /processForm and /callServlet not for url /Ask

It is not mapped to "/Ask". Remember that URLs are case-sensitive.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahtab Alam wrote:
What about first two questions


Those are the consequences and not separate problems.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!