Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2007

Tip: Looking for answers? Try searching our database.

HTTP 500 Tomcat help

Thread view: 
weeniejeff@gmail.com - 28 Jan 2007 01:07 GMT
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?
Nigel Wade - 29 Jan 2007 10:16 GMT
> Group,
>
[quoted text clipped - 47 lines]
>       } //end doPost
> } //end class

[...]
> 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)

I think that that message means that the class file which the classloader has
found in com/example/web/BeerSelect.class doesn't actually contain the class
for com.example.web.BeerSelect, but rather the class BeerSelect. Is there any
chance that the file contains an old version of the class which didn't have the
correct package declaration? Have a look at the contents of the class file
using javap, and see what it says for the class package.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Wojtek Bok - 29 Jan 2007 14:53 GMT
>     public void doPost(HttpServletRequest request, HttpServletResponse
> response)
>                 throws IOException, ServletException {

Try adding:

public void doGet(HttpServletRequest request, HttpServletResponse response)
  throws IOException, ServletException
{
  this.doPost(request,response);
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.