wood burning stoves*
The moose likes Cattle Drive and the fly likes 404 Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "404 Error" Watch "404 Error" New topic
Author

404 Error

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
I keep getting this error when I try to access Reverse2Servlet.
I have to go to localhost/servlet/reverse.jsp first. The page displays properly. When I click on submit, the browser can't find the servlet. I put all 3 copies of the class files that were formed when the servlet was compiled in the appropriate directory, ( the same one as BeeServlet.class ) BeeServlet works. Reverse2Servlet won't display.
Any suggestions? I've run out of ideas!
My servlet compiled okay, so I'm thinking that the browser should at least be able to locate it, even if it doesn't work as I hope it will.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Did you try
http://localhost/servlet/com.javaranch.drive.Reverse2Servlet
??
(I presume that you have the servlets in the C:\orion\default-web-app\WEB-INF\classes\com\javaranch\drive
directory)


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Hmmmm. Why are some directory names separated by forward slashes, and others by dots? I had all slashes before.
I now have this as my action attribute:

"http://localhost/servlet/com.javaranch.drive.Reverse2Servlet"

When I click on your link I now get this:

500 Internal Server Error
java.lang.NoClassDefFoundError: com/javaranch/drive/Reverse2Servlet (wrong name: Reverse2Servlet)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at com.evermind[Orion/2.0.5 (build 11234)]._as.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at com.evermind[Orion/2.0.5 (build 11234)]._ay._lse(Unknown Source)
at com.evermind[Orion/2.0.5 (build 11234)]._ay._cbd(Unknown Source)
at com.evermind[Orion/2.0.5 (build 11234)]._ay._nnc(Unknown Source)
at com.evermind[Orion/2.0.5 (build 11234)]._ax._luc(Unknown Source)
at com.evermind[Orion/2.0.5 (build 11234)]._ax._ucb(Unknown Source)
at com.evermind[Orion/2.0.5 (build 11234)]._bf.run(Unknown Source)

As far as I can see, everything is set up just like BeeServlet. There are 3
Reverse2Servlet class files because I copied the inner class example from BeeServlet. The files are where they should be, but there is something wrong with how they are named. I just noticed there are slashes here instead of dots. Could this have something to do with it?

java.lang.NoClassDefFoundError: com/javaranch/drive/Reverse2Servlet (wrong name: Reverse2Servlet)

Confusedly yours,
The Village Idiot


Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Okay, after playing around with my files, I'm back to the 404. Seems I'm driving in circles.
The error states that /servlet/com/javaranch/drive.Reverse2Servlet cannot be located. It is finding Reverse2Servlet instead.
Hmmmmmm, perhaps I'm compiling it in the wrong locale. I compiled the java file in C:\java\com\javaranch\drive and copied those class files to the appropriate location in orion. Nope, didn't work. Deleted the cache files to start fresh and compiled a copy of the same java file in C:\java and copied those class files to orion. Nope. Don't know why the message changed from 500 to 404, but at least the scenery has changed a little.
When I was dabbling with the jsp samples from more Servlets and JavaServer Pages ( thank you again, ME ) I recall having to compile the one involving packages in a directory of the same name before transferring the class file to orion.
Am I having a package problem here, or am I just hopelessly lost on the 404?
Wait, maybe I should be compiling a file named com.javaranch.drive.Reverse2Servlet in C:\java, and transferring those class files to orion. I'm going to go try that.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Okay, stupid idea. Forgot about the class name matching file name thing. I am just very confused. Why doesn't the server see the Reverse2Servlet class files? I can see them!
Kristin Stromberg
Ranch Hand

Joined: May 17, 2005
Posts: 91
Hi Carol, the action attribute should just include the path to the servlet (not the host name as well). I think Marilyn was suggesting you try accessing the servlet directly via your browser instead of calling it from your JSP just to see if it could be located that way.

For your action attribute in the JSP, you'll want to use something like '/the/path/goes/here/servletnamegoeshere'. For Servlets-2, you probably used '/servlet/ReverseServlet'.

Also, did you add anything to your web.xml file at all to help locate the Reverse2Servlet? If so, you probably need to refer to it differently in your jsp (use the shortcut, not the full path).

Hope this helps, but if not feel free to PM me with what you have so far and I will be happy to provide cryptic but encouraging hints (if I can figure out what's wrong).

Cheers!
Kristin Stromberg
Ranch Hand

Joined: May 17, 2005
Posts: 91
one more thing: your Reverse2Servlet class files are in the same subdir as the second BeeServlet example, and not the first, correct???
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Kristin, thanks for coming to my aid. I originally had the action attribute set to "/servlet/com/javaranch/drive/Reverse2Servlet" but that wasn't working; I saw an example somewhere that used the full address, so I changed it. Didn't help.
The Reverse2Servlet class files ( there are three ) are in orion's classes directory, in com/javaranch/drive directories alongside the BeeServlet classes.
Web.xml file? Don't have one of those. Web.xml isn't mentioned as a requirement for this assignment, so I haven't gone there yet.
Kristin Stromberg
Ranch Hand

Joined: May 17, 2005
Posts: 91
Okie doke. A couple of things:

1) I think you're supposed to start off with http://localhost/servlet/com.javaranch.drive.Reverse2Servlet and not with the JSP (just re-read your first post, and it looks like you might be starting with the JSP?).

2) Did you include the package statement at the top of your Reverse2Servlet file?

3) Does your Reverse2Servlet file contain a class named Reverse2Servlet?
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Originally posted by Kristin Stromberg:
Okie doke. A couple of things:

1) I think you're supposed to start off with http://localhost/servlet/com.javaranch.drive.Reverse2Servlet and not with the JSP (just re-read your first post, and it looks like you might be starting with the JSP?).

I'm using the jsp to see the form since the URL won't display anything but an error message.

2) Did you include the package statement at the top of your Reverse2Servlet file?

No. I've just got the two import statements. Perhaps this is where my problem lies?

3) Does your Reverse2Servlet file contain a class named Reverse2Servlet?
The top-level class is named Reverse2Servlet. The inner class is named Default, like the BeeServlet class.

I think the lack of a package statement might be the key!
I'll get back to you in a bit. Thanks!
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Okay. Now we have the page displaying when I go to the full URL. Thank you Kristin! It was a missing package statement.
Now I have to work on my servlet, because the 404 message shows when I click on submit, but at least I have a start.
I feel like I've made a little progress!
Tom Henner
Greenhorn

Joined: Jul 04, 2005
Posts: 18
Carol,
Keep after it! I really appreciate your posting versus going through the private message route. I will benefit greatly after I can get through the OOP section and into servlets. BTW, I don't understand why more people aren't active cattle drivers. It is the best $200 I've ever spent (for anything technical) :-) .

Tom
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Tom, I concur.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 404 Error
 
Similar Threads
The value attribute in Reverse2Servlet
Reverse2Servlet doXxx( question )
Reverse2Servlet
Reverse2Servlet
Reverse2Servlet