#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    49
    Rep Power
    13

    Question Help, servlet can be invoked by ANY name ?!


    I wrote a simple servlet that does nothing but outputs "hello world" to the browser. I used j2ee server and deploytool. I have set the context root to be "helloworld" in the deploytool. After deployment, I can access the servlet at

    http://localhost:8000/helloworld/*

    where "*" stands for ANY name! Is this supposed to be the behavior? I can access the servlet without using a more specific name related to the servlet class name?

    Thanks for help.
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Your web.xml must be set that way. Post it here. It is located in teh WEB-INF folder.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    49
    Rep Power
    13
    Originally posted by Nemi
    Your web.xml must be set that way. Post it here. It is located in teh WEB-INF folder.
    It's here:

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>

    <web-app>
    <display-name>HelloWorldWarDispName</display-name>
    <servlet>
    <servlet-name>HelloWorldServletCompName</servlet-name>
    <display-name>HelloWorldServletCompName</display-name>
    <servlet-class>HelloWorldServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorldServletCompName</servlet-name>
    <url-pattern>/HelloWorldAlias</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>HelloWorldServletCompName</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
    </web-app>
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    This is your problem:
    Code:
    <servlet-mapping>
    <servlet-name>HelloWorldServletCompName</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    If you remove that section you will only be able to access that servet by typing in:
    See how that servlet-mapping works? Basically, you said anything that comes in to this host will be returned by this servlet.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    49
    Rep Power
    13

    Unhappy


    I tried this, but the servlet is still accessible by any name. I tried to restart j2ee after the change, that also didn't work because each time j2ee is started, it re-generates that old web.xml file.
  10. #6
  11. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Regenerates the web.xml? How? Do you have a deployed war file it is extracting each time it starts?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    49
    Rep Power
    13

    Unhappy


    I do have a war file named "original.war" in the context root directory, when the j2ee server is shutdown, that's the ONLY file left in the directory tree, I still have META-INF, WEB-INF, and WEB-INF/classes directories, but they are ALL empty. When I start j2ee server, those directories are populated (web.xml, class file, etc, they will all disappear again if I shutdown the server).

    Maybe I forgot important option at the deployment?
  14. #8
  15. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    You should be able to do one of two things
    1) You can change the web.xml in whatever you orginally made it in and redeploy
    or
    2) You can extract the war file into the directories that the files are normally in and delete the war file. A war file is simply a zip file with another extension, so you can unzip it with any zip utility.

IMN logo majestic logo threadwatch logo seochat tools logo