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'
'
<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'
'
<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;
}
}
Web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC
'-//Apache Software Foundation//DTD Struts Configuration 1.1//EN'
'
<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;
}
}