Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet not displayed when called from browser - XML configuration problem?

 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi experts,
Below given is my simple servlet and the corresponding xml. I have put the servlet in WEB-INF/classes. When I call http://localhost:8080/myApp/Primitive from browser, HTTP Status 404(not available) is shown.

Kindly say, what can be the problem.



XML is

 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've configured it incorrectly.

First of all, you dont have to give the slash in front of servlet class. The servlet class item should have the fully qualified path name for the class file. Since, in your case, you havent added this as part of any package, you can just give the servlet name itself.

Now, in the web-app section, you need to add :

<servlet-name>Primitive</servlet-name>
<url-mapping>/Primitive</url-mapping> <!-- url-mapping is the URL to which this servlet is being mapped to-->

Try googling for some servlet deployment tutorial so that you can get a heads up on most of the common mistakes that we commit during web app deployment.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since, in your case, you havent added this as part of any package, you can just give the servlet name itself.

You should avoid using the default package and put the servlet in a proper package.

Now, in the web-app section, you need to add :

Enclosed in a servlet-mapping tag
 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dawn.
I tried exactly as you told, and here is my modified xml.
Unfortunately, it gives the same eror.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Did you restart the container ?
2. Put the servlet in a package
3. Which container are you using ? Which version ? You are using a configuration for Servlets 2.3, which looks a bit old. Check this.
4. Why are you implementing the Servlet interface ? I think you want to extend the HttpServlet class instead.
 
Ravindra Verma
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

replace <url-mapping> to <url-pattern>
 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. Did you restart the container ?
Yes

2. Put the servlet in a package
This has to work. After that I will do with package.

3. Which container are you using ? Which version ? You are using a configuration for Servlets 2.3, which looks a bit old.
I use apache-tomcat-6.0.18

4. Why are you implementing the Servlet interface ? I think you want to extend the HttpServlet class instead.
I am just trying out an example.

Kindly help with a solution.
 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to one and all. I tried each of your suggestions and ultimately, it got solved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!