Home > Archive > Java Help > March 2004 > tomcat servlet
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Hai Tran 2004-03-29, 10:36 am |
| 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) 2004-03-29, 1:56 pm |
| On 29 Mar 2004 06:39:45 -0800, Hai.Tran@qwest.com (Hai Tran) wrote:
>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>
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
>"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?
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 2004-03-30, 5:50 pm |
| 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?
"Bryce (Work)" <spamtrap@berzerker-soft.com> wrote in message news:<63ng60prkjfnkslrmsmt8sf61cc89jk013@4ax.com>...
> On 29 Mar 2004 06:39:45 -0800, Hai.Tran@qwest.com (Hai Tran) wrote:
>
>
>
> 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.
>
>
> 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>
>
>
> Yes, servlet-name is a reference to a servlet. You use that same name
> in servlet-mapping, etc.
>
>
> No. servlet-class is the class name of the servlet.
>
>
> No. url-pattern is the URL that is used by the servlet container
> (Tomcat) to know when to call your servlet.
>
>
> I'd suggest finding some servlet tutorials.
| |
| Bryce (Work) 2004-03-31, 9:51 am |
| On 30 Mar 2004 13:54:19 -0800, Hai.Tran@qwest.com (Hai Tran) wrote:
>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
|
|
|
|
|