File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Hard time learning Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Hard time learning Servlets" Watch "Hard time learning Servlets" New topic
Author

Hard time learning Servlets

Carsten Rasmussen
Ranch Hand

Joined: Sep 22, 2009
Posts: 65
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61760
    
  67

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.

    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Carsten Rasmussen
    Ranch Hand

    Joined: Sep 22, 2009
    Posts: 65
    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
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61760
        
      67

    Applet?

    Your servlet is still not in a non-default package.
    Your deployment descriptor has no mapping for the servlet.
    Virendrasinh Gohil
    Ranch Hand

    Joined: Jun 09, 2004
    Posts: 46
    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

    Joined: Sep 22, 2009
    Posts: 65
    Im not so god at english terms will someone please give an examble
    Carsten Rasmussen
    Ranch Hand

    Joined: Sep 22, 2009
    Posts: 65
    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
    Lester Burnham
    Rancher

    Joined: Oct 14, 2008
    Posts: 1337
    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

    Joined: Sep 22, 2009
    Posts: 65
    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/
    Mike London
    Ranch Hand

    Joined: Jul 12, 2002
    Posts: 1083
    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
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12835
        
        5
    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
    colin shuker
    Ranch Hand

    Joined: Apr 11, 2005
    Posts: 744
    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
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61760
        
      67

    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

    Joined: Sep 22, 2009
    Posts: 65
    Please show a whole example of that package thing please be so kind.
    Mike London
    Ranch Hand

    Joined: Jul 12, 2002
    Posts: 1083
    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Hard time learning Servlets