#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Malaysia
    Posts
    5
    Rep Power
    0

    Problem deploying a servlet


    Hi..

    I just start on Servlet programming....

    I used the default configuration from tomcat 4.1. I placed the servlet in the %catalina%/webapps/examples/WEB-INF/clases/ and it is working with http://localhost:8000/examples/servlet/MyServlet.

    However, I want to put the servlet under my own app directory for example called myApp. Then I put the class file in %catalina%/webapps/myApp/WEB-INF/classes/. But then it give an 404 error saying the requested source is not available when I try to access it using http://localhost:8000/myApp/servlet/MyServlet.

    I had check the <Context> tag in the %catalina%/conf/server.xml and found that the host is set to the following:-

    <Host name="localhost" debug="0" appBase="webapps"
    unpackWARs="true" autoDeploy="true">

    Where the autoDeploy is set to true.

    So, why is that I still can't access the http://localhost:8000/myApp/servlet/MyServlet ?

    Thanks.
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    autoDeploy is only for .war files.

    You need to create a new <Context> tag for your myApp directory. Just copy the tag for the examples context and modify appropriately.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Malaysia
    Posts
    5
    Rep Power
    0
    Thanks for your reply.

    I had just tested with the following :-

    <!-- myApp Context -->
    <Context path="/myApp" docBase="myApp" debug="0"
    reloadable="true" crossContext="true">
    <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="localhost_myApp_log." suffix=".txt"
    timestamp="true"/>
    <Environment name="maxExemptions" type="java.lang.Integer"
    value="15"/>
    </Context>


    I added the above directly below the <Context> for examples before the closing </host>. Anyway it doesn't work for me. Am I missing something here ?

    Thanks for the help.
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    It looks right to me. Try setting debug to 1 and seeing if you get any errors.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Malaysia
    Posts
    5
    Rep Power
    0
    No.. there is no error message.

    The funny thing is if I place a file say index.htm in %catalina%/webapps/myApp/index.htm

    The page work fine. The only thing is that the servlet cann't be found... It only give me a HTTP Status 404 with error :-

    The requested resource (/myApp/servlet/MyServlet) is not available.

    How do u think ?
  10. #6
  11. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, here's simplified <Context> tag:
    Code:
    <Context path="/myApp" docBase="myApp" debug="0" reloadable="true"/>
    Make sure your servlet is in
    Code:
    %catalina%/webapps/myApp/WEB-INF/classes
    it's case sensitive, so double check.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13
    bricker..

    i'm a novice j2ee guy...

    is the servlet directory automatically mapped to that application?
    or do you specify this in web.xml??

    i apologize if this is way off, and if i don't know what i'm talking about.. (i'm just learning)


    thanks
  14. #8
  15. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    It should be automatically mapped.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Malaysia
    Posts
    5
    Rep Power
    0
    I read in the books from New Riders.. the author say that the servlet should be deploy automatically if we put it under

    %catalina%/webapps/myApp/WEB-INF/classes
    We don't even need to set a <context> tag in

    %catalina%/conf/server.xml
    But, what happen to me that even if I set a <content> tag, it will not deploy also.

    I have doubled check and double checked again and again and tested both in my office pc and home pc. Both carry exactly the same configuration and code.

    I even copy the %catalina%/webapps/examples to rename it to myApp ... it's not working as well.

    Any suggestion ?
  18. #10
  19. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, I ran the problem down, but... I'm really confused now .

    Open your conf/web.xml file and look for the following lines:
    Code:
    <servlet-mapping>
            <servlet-name>invoker</servlet-name>
            <url-pattern>/servlet/*</url-pattern>
        </servlet-mapping>
    remove the comments around those and everything should work fine.

    My only question is, why was it commented out in the first place? In the examples folder they create a filter and a filter-mapping that maps the invoker servlet to servlet/*, so maybe that's the way they want it done now. I can't find anything in the documentation, though.

    Oh, and you where right about not needing to fiddle with the server.xml file. It should automatically find any apps you put into the webapps folder.
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Malaysia
    Posts
    5
    Rep Power
    0

    Thumbs up


    YES !!

    You did it It's working now ... hehehe...

    I'm so happy now :-D

    Thanks pal.
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    1
    Rep Power
    0

    Thumbs up bingo


    Bricker42 you rock!

    Nguip I must be using the same book as you. I had this exact problem.

    I did what you said Bricker42 and it worked. It seems very odd that that block of code would be commented out. Anyone know if using filters is the recomended way to deploy servlets now???
  24. #13
  25. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    I thought I posted back here to answer that. Oh well .

    Yes, filters are the recommended way to deploy a directory of servlets now. I guess there were some security concerns with using the old way.

    From what I've read, though, the *best practices* way to deploy servlets is to give each its own mapping in your deployment descriptor (web.xml).
    -james

IMN logo majestic logo threadwatch logo seochat tools logo