Java Servlet
We will now see how to implement a login application using Java Servlet. Create a new Dynamic Web Application in Eclipse as described in the previous section. We will call this LoginServletApp:
- Right-click on the
srcfolder underJava Resourcesfor the project inProject Explorer. Select theNew|Servletmenu option. - In the
Create Servletwizard, enter package name aspackt.book.jee_eclipse.book.servletand class name asLoginServlet. Then, clickFinish.

Figure 2.22: Create Servlet wizard
- The servlet wizard creates the class for you. Notice the
@WebServlet("/LoginServlet")annotation just above the class declaration. Before JEE 5, you had to declare servlets inweb.xmlin theWEB-INFfolder. You can still do that, but you can skip this declaration if you use proper annotations. UsingWebServlet, we are telling the servlet container thatLoginServletis a servlet, and we are mapping it to the/LoginServletURL path. Thus, we are avoiding the following two entries inweb.xmlby using this annotation...