tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject Re: Servlets directly accessible from browser
Date Sun, 31 Mar 2002 16:02:22 GMT
There are a couple concepts to understand here:

1. unless you provide a mapping to your servlet, the Servlet engine won't 
find it for you.  Servlets are not directly loadable.  Static files are (as 
are .jsp's).  Servlet mappings are set up in the web.xml.  In Tomcat, a 
default servlet mapping is set up for you for convenience: the directory 
"servlet" which comes after your context name.  So, that would be 

Now that we know that, this brings us to point #2.

2.  Either you must provide an alias for your servlet or reference it by 
its fully qualified name;  that being the package + classname.  If your 
servlet doesn't specify a package, then it would just be your ClassName.
Given no specified alias and the servlet belonging to package 
com.mycompany.servlets, your Counter servlet would be access like:


and if it doesn't have a package:


You can provide an alias by adding the following to your web.xml file 
(inside /test/WEB-INF/ directory):


Now you can actually access your servlet like this:


Notice that even though, in this case, the servlet was part of a package, 
you can still access it without referring to the package since you 
specified an alias for the servet.

You can do even more if you add your own mapping:


Now you can access the servlet without using the default mapping 
"/servlet/" since you are providing your own mapping:


notice how the "servlet-name" tag within the "servlet-mapping" tag is the 
same name as we specified in "servlet-name" tag within the "servlet" tag.

There are lots more complex examples that you can use by looking at the 
servlet spec or getting a good book on servlets such as Oreilly's Java 
Servlet Programming 2nd Edition, but this should get you started with what 
you need.


At 07:19 PM 3/31/2002 +0800, you wrote:
>Hi there,
>I have already set up a simple context at catalina_home/webapps/test/
>I have a few class files there (servlets). I find that I cannot directly
>execute them through the browser (e.g. localhost:8080/test/Counter to run a
>Counter.class servlet).
>Is it because of the way I write the servlets or must I add some
>configuration parameters to make all the servlets directly executetable?
>Thank you in advance.
>Yours truly,
>Do You Yahoo!?
>Get your free address at
>To unsubscribe:   <>
>For additional commands: <>
>Troubles with the list: <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message