Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cant run packaged servlet - Pz Help

 
Neelima Kalidindi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Tomcat 4.0, when I added a packaged class called HelloServlet2 under
<tomcat>\webapps\sjwcd\Web-inf\classes\moreserlvets\ and accessed it with the URL
localhost/sjwcd/servlet/moreservlets.HelloServlet2, I get a 404 File not available error.
But when I try the same directory structure and servlet from the examples directory, it works. It doesnt work from the root directory though.

I have setup a context path to /sjwcd in server.xml. Didnt have a web.xml for my application initially, but then I added one both with the same structure as examples\web-inf and root\web-inf, but to no avail.
What am I doing wrong ? How do I run a packaged servlet in tomcat ?
thanks
Neelima
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the exact same thing, except messing around with the server.xml.
It works for me.
Here are the steps that I did after reading your post:
  • Created a dir called "scwcd" under "webapps"
  • Created a sub-dir called "WEB-INF" in "scwcd"
  • Created a sub-dir "classes" in "WEB-INF" above.
  • Created a sub-dir "moreservlets" in "classes" above.
  • Copied the HelloServlet2.class file to the "moreservlets" sub-dir.
  • Copied the "web.xml", which with an empty "web-app" element into "WEB-INF"
  • Stop Tomcat and Start it again.
  • Access it through the URL http://localhost:8080/scwcd/servlet/moreservlets.HelloServlet2
  • The text "Hello (2)" shows up in the browser.


  • Check all your dir names. Remove the stuff in server.xml
    Good luck.
    - satya
     
    Neelima Kalidindi
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hmmm... I did the same, but still doesnt work. How did you compile the class ? I wonder if I compiled the class wrong.
    server.xml has no context for my application (scwcd). web.xml has an empty web-app tag. the package in HelloServlet2 reads :
    package moreservlets;
    The thing that bothers me is that I cant run this even from the Root\web-inf\classes\moreservlets directory. Infact, I cant run any of the examples packaged servlets from the root either! BUT, I can run it from examples directory. What about examples is special ???
    Neelima
     
    Madhav Lakkapragada
    Ranch Hand
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Can you run the Tomcat examples?
    You should also be able to run it from Root.
    To compile this I put servlet.jar and "." in my classpath.
    Also did you remove "sjwcd" from the server.xml?
    I think you said yes, right?
    - satya
     
    Neelima Kalidindi
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes, I can run tomcat examples and even my servlets when I try them out from the examples directory.
    I can run the examples from root only if the servlet is not packaged. For eg. I cant run the servlet cal.Entries from the root... I think its part of my problem.
    I've got servlet.jar and "." in my classpath for my compile window, though I dont have "." in my tomcat classpath.
    Yes, I removed sjwcd from server.xml and put a web.xml with an empty web-app tag in it.
    Can you run cal.Entries from root directory ?
    Neelima
     
    Madhav Lakkapragada
    Ranch Hand
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Got a class cast exception with the foll URLs:
    From scwcd webapp:
    http://localhost:8080/scwcd/servlet/cal.Entries
    From Root webapp: http://localhost:8080/servlet/cal.Entries
    This doesn't seem to be a good example.
    Anyother examples?
    - satya
     
    Neelima Kalidindi
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well, the fact that you're getting a classcast implies the servlet was run. In my case it doesnt go that far. It just cant recognize the servlet. I think something goofy with my classpath in tomcat. I will try a few more combinations and see if I can get this silly thing to run
    frustratedly
    Neelima
     
    Madhav Lakkapragada
    Ranch Hand
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Okay, take a deep breadth.
    Start from the scratch. For now forget the
    "sjwcd" web-app. Start with an all new webapp.
    Repeat the steps I mentioned above.
    Also, it would be helpful if you post your classpath. Did you change anything else in the "conf" directory?
    I will check this thread again in the night....
    gotto go....
    - satya
     
    Chintan Rajyaguru
    Ranch Hand
    Posts: 341
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    if you followed Satya's steps above, I cannot think why it should not work. Try this,
    (asuuming you are using Internet explorer)
    Go to Tools > Internet Options > Advanced (tab) > uncheck the item that says "show friendly http error messages"
    retry to access your servlet, now browser will show actual error instead of custom Internet Explorer error. This should give you a better clue
    Good luck
    Chintan
     
    Neelima Kalidindi
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Satya, Chintan,
    Donno what I'm doing wrong. I tried the exact same thing at work (tomcat 3.2.3 instead of 4.0) and I still see that /examples is somehow different from /scwcd or /servlet (for the root). My classpath out here is kinda long and work related, but its got servlet.jar and "." in it. No other tomcat specific entries in my classpath when I compile it. The tomcat startup script I use is also just setting the path to JDK. I will send you my classpath once I get home tonight.
    I took a deep breath, and created a new folder per Satya's instructions and still, /myfiles/servlet/moreservlets.HelloServlet says (after unchecking user friendly error messages on IE).
    "The requested URL /admin/servlet/ContextAdmin was not found on this server."
    I reverted back to my original server.xml so there is no mention of /myfiles in here. The web.xml file is empty.
    Could you give me your classpath, both for your java compiler window/ide and for your tomcat startup script ? Other than that I think we've got pretty much the same servlet setup. Will try this out again at home.
    Also, why do you say server.xml need not have a context for your web application ? Doesnt every web app need a context tag ?
    thanks for all the help... I hope things work when I get home...

    Neelima
     
    Neelima Kalidindi
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry wrong error message... the error message reads
    "The requested URL /myfiles/servlet/moreservlets.HelloServlet was not found on this server."
     
    Madhav Lakkapragada
    Ranch Hand
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    My CLASSPATH=.;D:\jakarta-tomcat-4.0.1\common\lib\servlet.jar
    Also, in the web.xml file the web-app element needs to be empty, but not the web.xml file.
    The web.xml will still contain the XML declaration as the first line and the DTD declaration in the next line. Then followed by the empty web-app element like this
    <web-app>
    </web-app>
    Just repeating this so that we are on the same page. Also I am not sure of the Tomcat 3.2 behavior, never tried it.
    One other thing I would verify, if you are working on a Windows system is the names of each folder. Windows doesn't seem to differentiate between "web-inf" and "WEB-INF or even "Web-INF" for that matter. So each file/dir name is important in a web app.
    Lastly, I hope you compiled the HelloServlet properly. I generally have something like "tutorial/src/moreservlet/HelloServlet.java" and compile it from "tutorial/src" using "javac moreservlets/*.java". Then copy the .class file under "WEB-INF/classes/moreservlets" folder.
    I will check back again after I get home....late in the night (ET)!
    - satya
     
    Neelima Kalidindi
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hello Satya,
    You were right... it was a problem with case sensitive path in windows ! There were two parts to my problem :
    1) the context path for "" (docbase="ROOT") was commented out on my server.xml and that seemed to have goofed up what URL-servlet mapping. For eg. I had HelloServlet.class both under ROOT\WEB-INF\classes and scwcd\web-inf\classes and all the time I was running the URL scwcd/servlet/HelloServlet, I thought I was running the class under my web app, but it was running stuff from the elsewhere. Once I uncommented out the ROOT path, things seemed to make a lot more sense i.e. my URL stopped working (as was expected due to the lower case web-inf)
    2) On windows 98, windows explorer displays WEB-INF as Web-inf, so thats the name I gave my directory too... like you said however, that didnt work. When I explicitly changed it to WEB-INF, all was well !
    thanks a ton for the patience and your suggestions !
    Neelima
     
    Madhav Lakkapragada
    Ranch Hand
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Now that you have installed Tomcat correctly and know how to do thing the right way, if I could ask please stay inthe forum and don't vanish.
    Keep posting here and make it a better place for learning.
    I do make this request in general, not you alone.
    Thanks.
    - satya
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic