March 27th, 2003, 01:59 PM
-
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.
March 27th, 2003, 04:16 PM
-
Your web.xml must be set that way. Post it here. It is located in teh WEB-INF folder.
March 28th, 2003, 10:06 AM
-
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>
March 28th, 2003, 10:47 AM
-
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.
March 28th, 2003, 01:16 PM
-
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.
March 28th, 2003, 01:51 PM
-
Regenerates the web.xml? How? Do you have a deployed war file it is extracting each time it starts?
March 28th, 2003, 02:18 PM
-
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?
March 28th, 2003, 06:33 PM
-
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.