Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2004

Tip: Looking for answers? Try searching our database.

tomcat servlet

Thread view: 
Hai Tran - 29 Mar 2004 15:39 GMT
I have browse through some of the posted notes on Tomcat Servlet and
couldn't find a fix. I am very new at this and any help is
appreciated.

I have installed MYQL and Tomcat 4.1 on WinXP. Manage to get the
Tomcat up and was able to view my app (myapp). Had my myapp in the
following directory:

c:/tomcat/webapps/myapp/WEB-INF/classes/ - contains all the java class
programs.

Web.xml contains:

<?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>
   <servlet-name>topper</servlet-name>
   <servlet-class>testme</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>topper</servlet-name>
   <url-pattern>/servlet/*</url-pattern>
 </servlet-mapping>
</web-app>

Created two simple hello java programs called "testme" and "abc123"
and put them under the "classes" directory. Had my URL pointer to
"http://localhost:7500/myapp/servlet/testme" which work for testme.
When I changed the URL to test the second program
("http://localhost:7500/myapp/servlet/abc123"), abc123, I only get
testme? Is there a way to set Tomcat so Tomcat will execute the any
classes from the URL?

1. Isn't servlet-name is just any name you give assign??
2. Servlet-class is the a test class program locate in the classes
directory so Tomcat knows where to look for all others???
3. url-pattern is the specify the URL pattern to expected return???

I am so confuse ...
Bryce (Work) - 29 Mar 2004 18:32 GMT
>Web.xml contains:
>
[quoted text clipped - 11 lines]
>  </servlet-mapping>
></web-app>

ok, nothing wrong with this, as long as:

1. the class (full class name, including any packages) is testme.class
2. Any URL with the pattern http://yourserver/servlet/* will be
directted to your server.

>Created two simple hello java programs called "testme" and "abc123"
>and put them under the "classes" directory. Had my URL pointer to
[quoted text clipped - 3 lines]
>testme? Is there a way to set Tomcat so Tomcat will execute the any
>classes from the URL?

Yes, because that's what you specified above.

You need 2 servlet declarations, such as:

<web-app>
 <servlet>
   <servlet-name>testme</servlet-name>
   <servlet-class>testme</servlet-class>
 </servlet>
 <servlet>
   <servlet-name>abc123</servlet-name>
   <servlet-class>abc123</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>testme</servlet-name>
   <url-pattern>/servlet/testme</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
   <servlet-name>abc123</servlet-name>
   <url-pattern>/servlet/abc123</url-pattern>
 </servlet-mapping>
</web-app>

>1. Isn't servlet-name is just any name you give assign??

Yes, servlet-name is a reference to a servlet. You use that same name
in servlet-mapping, etc.

>2. Servlet-class is the a test class program locate in the classes
>directory so Tomcat knows where to look for all others???

No. servlet-class is the class name of the servlet.

>3. url-pattern is the specify the URL pattern to expected return???

No. url-pattern is the URL that is used by the servlet container
(Tomcat) to know when to call your servlet.

>I am so confuse ...

I'd suggest finding some servlet tutorials.

--
now with more cowbell
Hai Tran - 30 Mar 2004 22:54 GMT
Bryce - Thank you so much for your help and clarification. To sum from
what you have said. I have to declare every servlet programs that will
be called in the web.xml file? Isn't there a dynamic or better way
other then declaring each servlet to be call?

Also, I've did purchase a book called "JSP, Servlets, and MYSQL by
David Harms" but it briefly mention it. Do you have other book
suggestion?

> >Web.xml contains:
> >
[quoted text clipped - 67 lines]
>
> I'd suggest finding some servlet tutorials.
Bryce (Work) - 31 Mar 2004 15:15 GMT
>Bryce - Thank you so much for your help and clarification. To sum from
>what you have said. I have to declare every servlet programs that will
>be called in the web.xml file? Isn't there a dynamic or better way
>other then declaring each servlet to be call?

Yes, each servlet must be declared in the web.xml file (as far as I
know). No, there is no dynamic way.

>Also, I've did purchase a book called "JSP, Servlets, and MYSQL by
>David Harms" but it briefly mention it. Do you have other book
>suggestion?

I don't know that book. I use the O'Reilly book "Java Servlet
Programming".

--
now with more cowbell


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.