• 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

Error 404

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I am a beginner with java and servlets so please be patient

I have tomcat 6.0.18 installed on Mac version 10.5.5

I am having a problem displaying my servlets. I am compiling my servlet and putting the class.file in:
~/webapps/ROOT/WEB-INF/classes

and to view the servlet i put in the browser address bar:
http://localhost/servlet/MyServlet

Please can some one point me in the rite direction

Thanks,
-Ben
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your servlets should be in a package other than the default in order to avoid dodgy errors.

Also, the /servlet/ prefix is no longer a valid way to invoke servlets, you need to map the servlet in the deployment descriptor.

Are you working with a very old tutorial?
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again Bear

Your servlets should be in a package other than the default in order to avoid dodgy errors.



Please could you explain this in a little bit more detail.

Also, the /servlet/ prefix is no longer a valid way to invoke servlets, you need to map the servlet in the deployment descriptor.

Are you working with a very old tutorial?



Sort of This was the method i was taught to run servlets in university, if this is wrong please could you explain what i need to do to fix the problem.

Thanks Bear
[ October 23, 2008: Message edited by: B Crosthwaite ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you familiar with Java packages? If not, that's a concept you need to wrap your mind around before writing servlets.

Servlets, and other classes intended for web applications, should never be in the default package.

Once that's settled, you need to declare and map your servlet in the web.xml file (deployment descriptor) in order to tell the container what URL corresponds to your servlet.
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have now changed my web.xml (~tomcathome/conf/web.xml) it has had the following code added to it:



and



Now when i type in the address bar http://localhost:8080/servlet/MyServlet i am presented with a blank page, no errors just blank.

Does anyone know what i am doing wrong?

-Ben
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So why are you enabling the Invoker rather than correctly mapping the servlet? The invoker is generally considered a very very very bad idea.

You've demonstrated that you know how to use the <servlet> and <servlet-mapping> elements -- use them to map your servlet and ditch the invoker.
[ October 24, 2008: Message edited by: Bear Bibeault ]
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

After Bears advice I tried to map my own servlet. I have come up with a different problem, ehe error i get is error 500. I have a feeling that is something really small.

Here is what iv done:

I edited the web.xml (~webapps/ROOT/WEB-INF/web.xml)


And in the web browser address bar i typed http://localhost:8080/hello

I think my problem is

<servlet-class>your.package.name.HelloWorld4</servlet-class>


But i could not find out what to put here.

If this is correct then i am lost again.

Any help would be appreitiated
-Ben
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is the package name in you servlet actually called "your.package.name"

when you create your project and create a new package what was the name you gave that package?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by B Crosthwaite:
ehe [sic] error i get is error 500.



500 is a general code for any exception that occurs on the server. There should be much more to the error message. Of particlaur interest will be the root cause.

But i could not find out what to put here.

That's where you put the class name (including complete package path) of your servlet class.
[ October 26, 2008: Message edited by: Bear Bibeault ]
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys, thanks for the quick replies.

The error 500 message is


java.lang.ClassNotFoundException: HelloWorld4.HelloWorld4
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:613)



So it is to do with the

<servlet-class>your.package.name.HelloWorld4</servlet-class>



When you say the

class name including complete package path of the servlet class


do you mean of the actual serlvet java file?

blow is the code of the servlet that i am trying to use.


-Ben
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your servlet is in the default package (no package declaration) you need to move it into a non-default package.

If packages are a Java concept that is not familiar to you, you need to get that under your belt before proceeding.
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please could someone provide me with some links to the appropriate information regarding the servlet packages and the <servlet-class>.

Obviously I have looked, but as this is new to me I just feel like I am going around in circles.

I would be very greatful.

Thanks,
-Ben
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there or is there not a package declaration in your servlet class? Do you or do you not know how to use Java packages?
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is there or is there not a package declaration in your servlet class



I dont know. How would i find out?

Do you or do you not know how to use Java packages?



No i dont.
When i think of packages i think of javax.servlet and javax.servlet.http etc

-Ben
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by B Crosthwaite:
I dont know. How would i find out?

It will be one of the first statements in the file, beginning with package.

Without it, your class is relegated to the default package which is problematic in web applications. It can sometimes be made to work, but it can also cause weird and difficult to diagnose problems. All your classes should be declared in a package other than the default.

No i dont.


Then you need to learn some more basic Java, such as packages, before diving off into servlets and more advanced concepts.

When i think of packages i think of javax.servlet and javax.servlet.http etc

Those are examples of Java packages. You need to learn how to create your own.

Once you've done that, then you'll know what to put into the <servlet-class> element. For example, one of my servlets could be declared as:
Note that the declaration contains the fully-qualified class name of the servlet, including its package.
[ October 27, 2008: Message edited by: Bear Bibeault ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic