Servlet HTTP 500 error

W

weeniejeff

Group,

I'm getting an HTTP 500 Status error using Apache Tomcat. I'm
learning Servlets and JSPs from the Head First book. I've searched
the groups and on the Internet, and can't seem to resolve my problem.

I have a webpage, form.html, that displays just fine with http://
localhost:8080/beer-V1/form.html. This web page is mapped in web.xml
to /BeerSelect.do:

- <servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>
</web-app>

BeerSelect.do maps the BeerSelect servlet class, which controls the
BeerExpert model.

BeerSelect:
package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BeerSelect extends HttpServlet {

public void doPost(HttpServletRequest request,
HttpServletResponse
response)
throws IOException, ServletException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");

BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();
while (it.hasNext()) {
out.println("<br>try: " + it.next());
}
} //end doPost

} //end class

is stored in C:\Apache\Tomcat6\webapps\beer-V1\WEB-INF\classes\com
\example\web\BeerSelect.class - it compiled just fine.

BeerExpert:
package com.example.model;
import java.util.*;

public class BeerExpert {

public List getBrands(String color) {
ArrayList<String> brands = new ArrayList<String>();
if (color.equals("amber")) {
brands.add("Jack Amber");
brands.add("Red Moose");
}
else {
brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}
return(brands);
}

}

is stored in C:\Apache\Tomcat6\webapps\beer-V1\WEB-INF\classes\com
\example\model\BeerExpert.class, and it compiled just fine.

When I hit the submit button on form.html, I get this HTTP 500 error:
java.lang.NoClassDefFoundError: com/example/web/BeerSelect (wrong
name: BeerSelect)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)

org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappCl
assLoader.java:1815)

org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoade
r.java:872)

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoade
r.java:1325)

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoade
r.java:1204)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.jav
a:105)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
212)

org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844)
org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:634)
org.apache.tomcat.util.net.JIoEndpoint
$Worker.run(JIoEndpoint.java:
445)
java.lang.Thread.run(Unknown Source)

I'm not sure what's going on... I can't seem to find what I'm
configuring incorrectly. Could someone please help?
 
Y

yasminevw

Group,

I'm getting an HTTP 500 Status error using Apache Tomcat. I'm
learning Servlets and JSPs from the Head First book. I've searched
the groups and on the Internet, and can't seem to resolve my problem.

I have a webpage, form.html, that displays just fine with http://
localhost:8080/beer-V1/form.html. This web page is mapped in web.xml
to /BeerSelect.do:
How does you're form.html look like? and how did you deploy the war
(web application) on you web server. Does it listen to a context-root?
From you url it looks like you're application is listing to the host
localhost at port 8080 and that you're using beer-V1 as a context
root, but if you type in the action "/BeerSelect.do" it looks for a
webapplication which listens to a web application a the '/' context
root.
Try to change the action in form.html to /beer-V1/BeerSelect.do.

The rest of you're code like ok to me.
 
D

Daniel Pitts

Group, [snip]
java.lang.NoClassDefFoundError: com/example/web/BeerSelect (wrong
name: BeerSelect)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
[snip]
I'm not sure what's going on... I can't seem to find what I'm
configuring incorrectly. Could someone please help?
It looks like somehow its finding the BeerSelect.class file, but the
class file doesn't have the right package name. Try deleting it and re-
compiling. It could be that you have an older class file, and it
wasn't compiled with the package declaration.

Hope this helps,
Daniel.
 
N

Nigel Wade

Daniel said:
Group, [snip]
java.lang.NoClassDefFoundError: com/example/web/BeerSelect (wrong
name: BeerSelect)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
[snip]
I'm not sure what's going on... I can't seem to find what I'm
configuring incorrectly. Could someone please help?
It looks like somehow its finding the BeerSelect.class file, but the
class file doesn't have the right package name. Try deleting it and re-
compiling. It could be that you have an older class file, and it
wasn't compiled with the package declaration.

Hope this helps,
Daniel.

and to the OP, do not multi-post. I've just wasted my time giving pretty much
exactly the same answer as this in another group to which the question was
multi-posted.
 
Joined
Jun 17, 2009
Messages
2
Reaction score
0
use this
<servlet>
<servlet-name>SelectBeer</servlet-name>
<servlet-class>BeerSelect</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SelectBeer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>
 
Joined
Jun 17, 2009
Messages
2
Reaction score
0
use this

<servlet>
<servlet-name>SelectBeer</servlet-name>
<servlet-class>BeerSelect</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SelectBeer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top