views:

251

answers:

3

I am trying to call a Servlet called AddClass.java using the following line in a jsp

<form method="post" name="addClass" action="AddClass.do">

The class is in package web and the filename is AddClass.java

A similar servlet named SeedSearch is called (and everything works fine) from this piece of code in another jsp.

<form method="post" name="seedSearch" action="SeedSearch">

My web.xml looks like this

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>sempedia</display-name>

<servlet>
  <servlet-name>SeedSearch</servlet-name>
  <servlet-class>web.SeedSearch</servlet-class>
</servlet>
<servlet>
  <servlet-name>AddClass</servlet-name>
  <servlet-class>web.AddClass</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>SeedSearch</servlet-name>
  <url-pattern>/SeedSearch</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddClass</servlet-name>
<url-pattern>/AddClass.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
 </welcome-file-list>

</web-app>

Please help.

+1  A: 

There's no leading '/' in your call to SeedSearch.

Steve B.
Hi Steve, actually the same error occurs without the / - I added that in desperation hoping it might change things. I have removed it, as that is the way the code is.
Ankur
It would only return 404 if there's a context.
BalusC
+1  A: 

Perhaps you are mapping "*.do" in somewhere else (struts may be?) and your servlet is never called.

Aito
Thanks for your suggestion, but I just added the .do to try something different and I have not used struts on this machine ever.
Ankur
+1  A: 

The web.xml looks fine, so the problem lies somewhere else.

  1. URL is plain wrong. Relative URL's must be extracted from its absolute form based on the current request URL or -if any- the HTML <base> tag. Take care: the leading slash takes you to the domain root! This is not necessarily the correct solution as others here seem to think, especially not if webapp has a context path.
  2. Package/classname in web.xml doesn't match actual Servlet class (casesensitive!)
  3. Servlet class isn't in the classpath of the running webproject. At least, not at the expected location.
  4. Servlet class failed to load/initialize. Read appserver logs for exception/error details.
  5. There's actually more in web.xml, e.g. another servlet which eats *.do and got precedence.
  6. You aren't running the webproject with the particular web.xml you think you are. Doubleverify, rebuild, redeploy and restart.
BalusC
Thanks very useful as a general checklist, I am sure someone will find that list useful in the near future.
Ankur