Wednesday, September 7, 2011

Web.xml is optional

web.xml is optional. This is one of the feature of Servlet 3.0

So how to specify urlpattern and name of the servlet. Let see this in the following lines.

instead of using web.xml , annotate the servlet class with @WebServlet as below.

@WebServlet(name="NewServlet", urlPatterns={"/NewServlet"})
public class NewServlet extends HttpServlet {

}

name specifies name of the servlet and url patter specifies url pattern of the Servlet .

Run the application and start playing.