• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Hard time learning Servlets

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My config look like this:
/webapps/index/WEB-INF/classes/

My /index/WEB-INF/web.xml look like this:


In index/WEB-INF/classes/ i have

Witch is just a test servlet i have download.

I cant load Index/ or my servlet it gives class not found and somehow tries to load my servlet as index/ in manager.
I'm using Ubuntu Lucid and Tomcat 6 please help i have been trying for hours and my head hurts.
What i'm i doing wrong ???
Thank you
 
Sheriff
Posts: 67734
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
You're doing a number of things wrong which lead me to believe that you are using some very old information:
  • You are using the invoker. Stop. Don't.
  • All classes used in a web application must in a package other than the default.
  • Your web app is declared as a 2.3 DTD web app. For Tomcat 6 it should be using the 2.5 schema.


  • What are you using for a reference. It's either very old or very bad.
     
    Carsten Rasmussen
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I changed my web.xml to:


    Same error, it tries to employ the applet as default page and dont starts.
    /index Zjat Beta false 0 Start Stop Reload Undeploy
     
    Bear Bibeault
    Sheriff
    Posts: 67734
    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
    Applet?

    Your servlet is still not in a non-default package.
    Your deployment descriptor has no mapping for the servlet.
     
    Ranch Hand
    Posts: 46
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Carsten Rasmussen wrote:I changed my web.xml to: Same error, it tries to employ the applet as default page and dont starts.
    /index Zjat Beta false 0 Start Stop Reload Undeploy



    Also, the </servlet> must have starting <servlet> tag. Incorrect indentation leads to such problems. And as Bear Bibeault said, where is servlet-mapping?
     
    Carsten Rasmussen
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Im not so god at english terms will someone please give an examble
     
    Carsten Rasmussen
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I changed my web.xml to:


    And it loads the page in Manager but i cannot see index.jsp and servlet gives this error:


    Why oh why must it be, please help
     
    Rancher
    Posts: 1337
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What object is null at line 42 in zjat.java? Why is it null? Why is the code assuming that it would not be null?
     
    Carsten Rasmussen
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry my bad, i had change something i shouldent had change, the script is ok.
    But why can't i see front page in index/
     
    Bartender
    Posts: 1954
    17
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I'd recommend using MyEclipse, Intellij IDEA, or a tool that helps you get the configuration correct so you don't have most of these problems.

    Try a simple Servlet example first. Look at "Coreservlets.com" or pick up a copy of Marty Hall's book "Core Servlets and JavaServer Pages".

    Once you get one working, with a good IDE, it's simple from there.

    - mike
     
    Author and all-around good cowpoke
    Posts: 13078
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Wrong


    Right


    That is what was meant by the earlier comment that ALL Java classes used in servlets MUST be in a package.

    A class without a package is in the "default" package - a JVM looks for default classes in the "current" directory, something you have no control over. By using a package you force Tomcat to look in the web application for the class file.

    Tomcat usually come with a file "class-loader-howto.html" which explains how Tomcat locates classes.

    Bill
     
    Ranch Hand
    Posts: 750
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Netbeans is pretty good, I like the deployment descriptor, its easy to add servlets, you don't need to see the xml, but you can if you want.
     
    Bear Bibeault
    Sheriff
    Posts: 67734
    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

    colin shuker wrote:Netbeans is pretty good, I like the deployment descriptor, its easy to add servlets, you don't need to see the xml, but you can if you want.


    Which is why I think it's a very bad idea to rely upon IDE's at the outset. If it hides things from you, how are you going to learn how to do it without the crutch?
     
    Carsten Rasmussen
    Ranch Hand
    Posts: 65
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Please show a whole example of that package thing please be so kind.
     
    Mike London
    Bartender
    Posts: 1954
    17
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Bear Bibeault wrote:

    colin shuker wrote:Netbeans is pretty good, I like the deployment descriptor, its easy to add servlets, you don't need to see the xml, but you can if you want.


    Which is why I think it's a very bad idea to rely upon IDE's at the outset. If it hides things from you, how are you going to learn how to do it without the crutch?



    I partly agree with Bear, but if you're under pressure to produce code (and why we're, as developers, subjected to "XML-Configuration-Hell" with all the Java components I don't know...), then an IDE is a good way to get a *working* example.....THEN look at the code to see how it's put together if you need/want to. Otherwise, just deliver your code unless you're being paid to explain the XML configuration files! ;)

    A clear Java book with good examples where you're not typing in code, but trying to understand concepts separately is also something I do.

    Also, if you're a student, then Bear is right, but in that case, I'd still recommend at least using TextPad so you have a somewhat Java-aware editor.

    Eclipse can be a little overwhelming if you're new to everything.

    HTH

    -- Mike
     
    Yup, yup, yup. Tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic