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.
The moose likes Servlets and the fly likes problems with web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problems with web.xml " Watch "problems with web.xml " New topic
Author

problems with web.xml

rakhee vissa
Greenhorn

Joined: Aug 19, 2006
Posts: 4
Hi there,
I am trying to create my first web app servlet working in a folder- murach.It has an email form, which passes the parameters to a page using servlet. I am using Tomcat 5.5
I have placed web.xml in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\murach\WEB-INF\classes
I am also using the same web.xml as in the servlets-examples folder in Tomcat 5.5. I have made the following changes to my web.xml in order to get my application working. This hint I got from one of the forum discussions in JavaRanch.
<servlet>
<servlet-name>EmailServlet</servlet-name>
<servlet-class>email5.EmailServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EmailServlet</servlet-name>
<url-pattern>/servlet/email5/EmailServlet</url-pattern>
</servlet-mapping>
*******
Then, I put the Context tag in server.xml which is in C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf
My Context tag looks like this:
<Context path="/murach"
docBase="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\murach"
reloadable="true" debug="0"/>

Still, I am not able to run the servlet when I go through the html page, which is :
http://localhost:8080/murach/join_email_list.html
The moment I hit SUBMIT button, it shows
http://localhost:8080/servlet/email5.EmailServlet?firstName=kiran&lastName=kumar&emailAddress=kirankumar%40yahoo.com
in the address bar and says,
404 -FILE NOT FOUND ERROR

I am not able to figure out why is this showing like this. I would really appreciate if somebody could help me out with this!!
-Thanks
Sujith Kanaparthi
Ranch Hand

Joined: Sep 04, 2005
Posts: 45
I have worked with tomcat a little bit...the URL mapping is wrong


Intead of <url-pattern>/servlet/email5/EmailServlet</url-pattern>
use <url-pattern>/EmailServlet</url-pattern>

Hope this may help you
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You don't need to alter your server.xml file if your webapp is under the 'webapps' directory. Tocmat will take care of deploying it for you.

You also don't need to put "servlet/" in the url-mapping.
You can if you want to but it's not requires.
The use of 'servlet/..' was required back when the (now deprecated) invoker servlet was common in Tomcat apps.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
rakhee vissa
Greenhorn

Joined: Aug 19, 2006
Posts: 4
Originally posted by Ben Souther:
You don't need to alter your server.xml file if your webapp is under the 'webapps' directory. Tocmat will take care of deploying it for you.

You also don't need to put "servlet/" in the url-mapping.
You can if you want to but it's not requires.
The use of 'servlet/..' was required back when the (now deprecated) invoker servlet was common in Tomcat apps.


Thank you.. I got it working!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problems with web.xml