Servlet Annotation WebServlet Example

First example to show Servlet Welcome. For this we have created index.html page on index.html we have created a link. on click at link it will call welcome servlet.

Our project directory structure is as below

1_expo

index.jsp

Welcome.java

@WebServlet(name = “Welcome”, urlPatterns = {“/welcome”}) here urlPattern maps /welcome to Welcome.java.
<a href=”welcome”>Show welcome servlet</a> call to doGet() method of Welcome.java because anchor tag calls http get method so it is handled by servlets doGet() method.

Result
1_first

1_second

Leave a Comment