By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Could not get Tomcat Servlet to be recognize

P: n/a
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\webapps\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?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Hai Tran" <Ha******@qwest.com> wrote in message
news:33**************************@posting.google.c om...
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\webapps\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.Hello</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.Hello</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.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.