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
src
folder underJava Resources
for the project inProject Explorer
. Select theNew
|Servlet
menu option. - In the
Create Servlet
wizard, enter package name aspackt.book.jee_eclipse.book.servlet
and 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.xml
in theWEB-INF
folder. You can still do that, but you can skip this declaration if you use proper annotations. UsingWebServlet
, we are telling the servlet container thatLoginServlet
is a servlet, and we are mapping it to the/LoginServlet
URL path. Thus, we are avoiding the following two entries inweb.xml
by using this annotation...