This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hi all, I have a question regarding the <servlet-mapping> in web.xml file. I would like to know if it is a must to have servlet-mapping for every servlet in the web.xml file. I have written a TestServlet and did not give its <servlet-mapping> in the web.xml file. I was not able to give the correct path in webform for POST action. If I donot give <servlet-mapping>, what would be exact path of this servlet, if i need to access this from some webform for POST or GET action. EXAMPLE: form.html:
In the above web.xml file, since i dint give any servlet mapping, i have tried to access the TestServlet in POST action in form.html by giving path: "TestServlet". But this did not work. But once i have changed the web.xml file to :
Now I tried to access the servlet in the webform by giving path "TestServlet" for POST action. This time it worked. If <servlet-mapping> for every servlet is not a must, then please help me giving correct path to access TestServlet in the form.html file. thanking you pradgum
Instead of using /TestServlet/* in the web.xml for the mapping, use /TestServlet. In your form action try "/<youAppDirectory>/TestServlet" The only way if you don't want to write you mapping in the web.xml is to use the ServletLoader class that is provide by your App Server Provider. I think their is one with Tomcat but i'm not sure. You can call a servlet by giving is full name. Ex: http://localhost:8080/servlet/com.sparebrain.servlet.MySampleServlet Hope this help