Servlet Using Annotation
Servlet can be create with the help of @WebServlet bServlet annotation. This will not require any entry the deployment descriptor web.xml file.
Annotation got introduced as part of servlet 3.0
Please find below list for some other annotations:
@WebInitParam This is to specify init param earlier used to define as part of <init-apram> tag.
@WebFilter: It helps us to declare a servlet filter.
@WebListener: It helps us to declare a WebListener
Example
Servlet class needs to extends HttpServlet class and define @WebServlet annotation on top of the class.
Below will be the content required in web.xml
Right click on the project and select Run As and then Run on Server to run application on Apache Tomcat.
Hit below url in browser to get an output.
http://localhost:8082/ServletDemo/login
OUTPUT
Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.