Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems with web.xml

 
rakhee vissa
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rakhee vissa
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic