×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

NoClassDefFoundError: javax/servlet/http/HttpServlet

NoClassDefFoundError: javax/servlet/http/HttpServlet

NoClassDefFoundError: javax/servlet/http/HttpServlet

(OP)
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="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
    'http://java.sun.com/dtd/web-app_2_3.dtd'>

<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="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE struts-config PUBLIC
    '-//Apache Software Foundation//DTD Struts Configuration 1.1//EN'
    'http://jakarta.apache.org/struts/dtds/struts-config_1_1...'>

<struts-config>

  <message-resources parameter="wiley.ApplicationResources"/>

  <form-beans>
    <form-bean name = "lookupForm" type = "wiley.LookupForm" />
  </form-beans>

  <action-mappings>
    <action path = "/Lookup"
      type = "wiley.LookupAction"
      name = "lookupForm"
      input = "index.jsp">
      <forward name = "success" path = "/quote.jsp" />
      <forward name = "failure" path = "/index.jsp" />
    </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("SUNW")){
        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("success");

    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("failure");
    }
    else {
      request.setAttribute("PRICE", 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;
  }
}

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

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="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
    'http://java.sun.com/dtd/web-app_2_3.dtd'>

<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

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

(OP)
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.

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

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

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

(OP)
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.

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

What is the class that it's complaining about NoClassDefFoundError?  Any more details on the error output?

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

(OP)
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.

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

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

RE: NoClassDefFoundError: javax/servlet/http/HttpServlet

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close