![]() When we annotate our filter class with annotation the container will be able to recognize this as a filter at the loading time.Ĭlass annotated with still needs to implements the Filter interface 3 annotation is the replacement of filter configuration in web.xml. Lets modify above Welcome Servlet’s web.xml to add two init params like below Ĭorrespondingly WelcomeServlet code will be modified like below package One annotation is needed for one init param tag and all annotation are configured in initParams attribute of annotation. Remember we can define multiple init parameters for a servlet which we can get in the servlet using servlet config enables us to configure one init param and provides name, value and description attribute. Protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExceptionĭid you notice the word “urlPatterns”? it is not a pattern, it is patterns which means we can map a servlet with multiple URLs description="Welcome Servlet") 18.2.2 annotation is used for init-param configurations of servlet. Protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException Private static final long serialVersionUID = 1L Public class WelcomeServlet extends HttpServlet initParams – takes multiple annotation.loadOnStartup – defines the value of load on start up.urlPatterns – maps the servlet to the pattern.With this approach, we need not to configure any entry in web.xml for Welcome Servlet. ![]() annotation is highlighted below and all the attributes configured in web,xml are configured in annotation itself. Same servlet configuration can be done with annotation as shown below. Lets take an example Welcome Servlet which is defined in an web.xml like below With this annotation we can specify servlet-name, url-mapping, load on Start up, description ,init params ,async supported etc When we annotate our servlet class with annotation the container will be able to recognize this as a servlet at the loading time.Ĭlass annotated with still needs to extends the HttpServlet class 18.2 Annotation Details 18.2.1 annotation is the replacement of servlet configuration in web.xml. ![]() In this chapter we will discuss the important and most commonly used annotations. The Annotation based configurations makes the code more readable and also saves us from maintaining deployment descriptors. As we discussed in earlier chapter that Servlets 3.0 has come up with a set of new Annotations for the Servlets, Init-Params, Listeners, and Filters that makes the use of Deployment Descriptor ( web.xml) absolutely optional.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |