• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

404 Error

 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom, I concur.
 
Don't play dumb with me! But you can try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic