1

Context:

  • Learning Servlets and JSP
  • Eclipse Version: Mars.2 Release (4.5.2)
  • Tomcat Version: 8.0.33
  • Java 8

Question:

Is the web.xml purely ceremonial? It doesn't appear to be useful in any way, although I am early in the learning process. I thought it was used for default url mapping but I just put an index.html file in the project and it apparently automatically maps it for me! I also thought it was for defining the servlet but Eclipse automatically uses the @WebServlet annotation which apparently replaces it? Am I being naïve or is it not very useful?

Daniel
  • 31
  • 3
  • An index.html file is listed as a welcome file in Tomcat's web.xml file which is located in Tomcat's conf folder. The default values are there in case your web app doesn't set any values. – rickz Jul 26 '16 at 20:00

1 Answers1

1

Well, its is not historical in the sense that it has no use. You still can use it to e.g. enhance/overwrite the defaults. Also, error page mappings as one example have to be done via the web.xml. But you are right that e.g. for serlvet definitions you can use the annotation approach.

Cheers, Daniel

38leinad
  • 196
  • 2
  • 11
  • 1
    Is there a preferred approach? Or is it left up to the programmer? – Daniel Jul 26 '16 at 17:23
  • 1
    as the annotation-based approach is simpler to mock something up (just add the annoation, thats it), i would always start with it. if you are writing a serious application you at some point will have to define a web-xml for the parts that cannot be done via annotations. so, start out without web.xml and if you than e.g. need to define error-pages for certain exceptions, define the web.xml for these "more" verbose configurations. – 38leinad Jul 27 '16 at 07:13