Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NoClassDefFoundError: javax/servlet/http/HttpServlet

Status
Not open for further replies.

cabro

Programmer
Jan 30, 2004
5
US
I'm going through the Wiley/Mastering Jakarta Struts book. On the first Struts appilcation I get the NoClassDefFoundError. I've been banging my head against the wall for about 2 weeks now trying to figure this one out. It's probably something obviously simple but I can't find it. Everything compiles fine. The servlet-api.jar is in my common/lib folder and in the classpath. A simple servlet using HttpServlet runs fine. I don't get the error until I try to do struts. The error occurs when I start the server and it is deploying the application. I also get the same error when I add the struts-example and struts-documentation apps that came in the struts.zip file to my webapps folder. Here's the files for my app although I don't think that is the problem since I get it for the sample struts apps also. It must be something with my configuration. Also - I am using Tomcat. - If there is anything else useful I can post please let me know. Any help would be much appreciated.

Web.xml
<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>

<!DOCTYPE web-app
PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
'
<web-app>

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

Struts-config.xml
<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>

<!DOCTYPE struts-config PUBLIC
'-//Apache Software Foundation//DTD Struts Configuration 1.1//EN'
'
<struts-config>

<message-resources parameter=&quot;wiley.ApplicationResources&quot;/>

<form-beans>
<form-bean name = &quot;lookupForm&quot; type = &quot;wiley.LookupForm&quot; />
</form-beans>

<action-mappings>
<action path = &quot;/Lookup&quot;
type = &quot;wiley.LookupAction&quot;
name = &quot;lookupForm&quot;
input = &quot;index.jsp&quot;>
<forward name = &quot;success&quot; path = &quot;/quote.jsp&quot; />
<forward name = &quot;failure&quot; path = &quot;/index.jsp&quot; />
</action>
</action-mappings>

</struts-config>

The class files:
LookupAtion.java
package wiley;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LookupAction extends Action {

protected Double getQuote(String symbol) {
if (symbol.equalsIgnoreCase(&quot;SUNW&quot;)){
return new Double(25.00);
}
return null;
}

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

Double price = null;

//Default target to success
String target = new String(&quot;success&quot;);

if (form != null ) {
//Use the LookupForm to get the request parameters
LookupForm lookupForm = (LookupForm)form;
String symbol = lookupForm.getSymbol();
price = getQuote(symbol);
}
// Set the target to failure
if ( price == null) {
target = new String(&quot;failure&quot;);
}
else {
request.setAttribute(&quot;PRICE&quot;, price);
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}

LookupForm.java
package wiley;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LookupForm extends ActionForm {
private String symbol = null;
public String getSymbol() {
return (symbol);
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.symbol = null;
}
}
 
Hi,

The exception occurs with the config files. Just make sure you have all the necessay jar file and tld's in your web appliction.

Change the order of the web.xml and try, hope this will help you.

<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>

<!DOCTYPE web-app
PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
'
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
</web-app>

Cheers,
Venu
 
Thanks - I tried the re-order of the web.xml. No luck yet.

The servlet-api.jar is in my common/lib folder, the struts-html.tld is in my webapps/wileystruts/WEB-INF folder along with the other .tld's. I have wipped out my entire Tomcat install and started over from scratch several times. I'm just missing something somewhere and can't seem to catch it.
 
Hi,

Where is the struts.jar file is it in TOMCAT_HOME/common/lib or webapps/wileystruts/WEB-INF/lib ? You need to have this jar file in your classpath along with the other required jar files which come along with download.

Cheers,
Venu
 
Thanks again

I have the struts.jar, struts-legacy.jar and 7 other commons-*.jar files in my webapps/wileystruts/WEB-INF/lib.

In the TOMCAT_HOME/common/lib folder I have another group of common-*.jar's, several other jsp-*.jar's, jmx-*.jar's, naming-*.jar's and the servlet-api.jar and xerces.jar.

I can't think of anything else to pass on at the moment.
 
What is the class that it's complaining about NoClassDefFoundError? Any more details on the error output?
 
The class it says it can't find it the HttpServlet - the servlet-api.jar. I have it in the TOMCAT_HOME/common/lib which is where it came in Tomcat.
 
Hi,

Can you just extract the servlet-api.jar and check for the file HttpServlet.java. Just make sure, if not remove that and copy serlvet.jar.

Cheers
Venu
 
I've checked the servlet-api.jar for the class and it's there - everything looks good (I also had someone else more experienced take a look also). My compile of the .class files works fine too so it's finding it then.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top