I am new in to web development. I started reading Head first Servlet and JSP from Kathy Sierra.
And i am bit confused about the role of web.xml.
I understand that it helps to find the right servlet with <servlet-mapping> and i understand everything else about it.
But as far as i could understand then I think controller looks into this xml( in /WEB-INF) and finds the correct servlet class tat exists in tomcat dir as well
So why do we need to create it in development environment.
like in the Beer-v1 etc directory we have.
I tried to remove this file from etc directory and it had no effect. I was able to see the web page with no prob.
So can anyone please help me understand this concept .
If you do have only a static content, you don't need to have a web.xml file, but if you do have a dynamic content, you have to "tell" the container what servlet do you mean by typing an URL.
The great power of web.xml is that you can map one servlet on multiple URL paths which doesn't have to share the same name, so you can have a MyServlet.java but you can map it to /myApp/temp/myServ.
How could you achieve this without a web.xml? Also remember, that everything in /WEB-INF/ directory is never directly available to the outside world.
By the controller in "controller looks into this xml( in /WEB-INF)" you mean the container, right?
In JEE 6 (Servlets 3.0) you can move a lot of Deployment Descriptor entries into the Java annotations. So, i.e. you can use @WebServlet annotation instead of <servlet> and <servlet-mapping> elements.
OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Joined: Feb 11, 2009
First of all thanks for your reply Pedro.
Now the role of web.xml is clear but i still don't understand what if we don't have web.xml in beerV1\etc and just create a web.xml in Tomcat 7.0\webapps\Beer-v1\WEB-INF
I try to remove beerV1\etc and my web app was working without any error.
May be its a very stupid question and reflects that my basics of web development is not clear yet. but thats what i am here to do
Can you please elaborate it a lil bit more.
I might just suspect that you are messing the development environment (where the HF book suggest the /etc directory) and the deployment environment (where you have a /WEB-INF).
Firstly, please show me your project structure (you know - where the *.java files are located in, where the web.xml is located, etc.)
Secondly, please show me your deployment structure (which is TOMCAT_HOME/webapps/yourWebApp/.... etc.)
After making sure where the problem lies, we could figure out how to solve it :-)