"Hai Tran" <Ha******@qwest .com> wrote in message
news:33******** *************** ***@posting.goo gle.com...
Any help is appreciated.
Installed Tomcat 4.1 and Mysql on a WinXP. I've manage to get Tomcat
up and was able to view my first application ( myhome ) simple home
page. Tomcat was installed under C:\Tomcat4\ with
C:\Tomcat4\weba pps\myhome\WEB-INF\classes to store all my java.class
files. Under WEB-INF, I've have edit the web.xml file as
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>
<servlet-mapping>
<servlet-name>
invoker
</servlet-name>
<url-pattern>
/servlet/
</url-pattern>
</servlet-mapping>
</web-app>
After creating simple compile "hello.java " java program and place
under the classes directory, I've tried to see if the servlet will
work by targeting the URL to
http://localhost:7500/myhome/servlet/hello. This did not work. Also by
calling the servlet from another html page "/servlet/hello" did not
work either.
could someone help?
Fist, you're missing a <servlet> tag, like:
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>com.foo.H ello</servlet-class>
</servlet>
where the servlet-name matches the servlet-name in your servlet-mapping and
servlet-class is the fully qualified java name of the class file. Second, a
url-pattern of /servlet/ means you'd type:
http://localhost:7500/myhome/servlet/
to access it. So you want something like this in your deployment descriptor:
<?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>
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>com.foo.H ello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/invoke</url-pattern>
</servlet-mapping>
</web-app>
This assumes that you have the servlet Hello.class in the
/WEB-INF/classes/com/foo directory, and you would call the servlet like
this:
http://localhost:7500/myhome/invoke/
In the future, please post to comp.lang.java. help for simple questions or
comp.lang.java. programmer for advanced questions. This group is not carried
by all news servers.