You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Alexey V. Meledin" <av...@webclub.ru> on 2000/04/08 15:09:20 UTC

Can I start servlets by extension or I need to change web.xml everytime.

Hi!

  Anybody knows how to start servlets by extention?
  Users need a possibility to write and run their own servlets,
  without changing web.xml file and tomcat restart.

Alexey V. Meledin <av...@webclub.ru>
> InterForge Developers Group,  St-Petersburg, Russia
New: http://www.crossroad.ru; http://www.garoway.com
> > > > > > "InterForge to Forge Ahead" > > > > > > >



Re[2]: Can I start servlets by extension or I need to change web.xml everytime.

Posted by "Alexey V. Meledin" <av...@webclub.ru>.
Hi,
 Peter!

PS> I'd love to RTFM, but I haven't found any FM yet :) Is there any documentation
PS> at this point (for Tomcat in general I mean)?
I need it either.

Alexey V. Meledin <av...@webclub.ru>
> InterForge Developers Group,  St-Petersburg, Russia
New: http://www.crossroad.ru; http://www.garoway.com
> > > > > > "InterForge to Forge Ahead" > > > > > > >



Re: Can I start servlets by extension or I need to change web.xml everytime.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
See below.

Peter Schuller wrote:

> Hello,
>
> [my attempted servlet mapping]
> > >         <servlet-mapping>
> > >             <servlet-name>
> > >                 invoker
> > >             </servlet-name>
> > >             <url-pattern>
> > >                 *.class
> > >             </url-pattern>
> > >         </servlet-mapping>
> > >
>
> > The basic source of information is the Servlet API Specification, version 2.2,
> > which you can download from <http://java.sun.com/products/servlet/download.html>.
> > Section 10 talks about how mappings work.
>
> Ah. I didn't realize Tomcat (or rather, the Servlet framework) was
> application centric nowadays. Thank you.
>
> > Now, you let's assume that you have done this in a web application whose context
> > path is "/myapp", and the complete URL to access this app is:
> >
> >     http://localhost:8080/myapp
> >
> > Now, you might use the following types of mappings:
>
> [snip]
> >     <!-- Process all GIF images myself, instead of
> >         letting the default file-serving servlet serve them. -->
> >     <servlet-mapping>
> >         <servlet-name>myservlet</servlet-name>
> >         <url-pattern>*.gif</url-pattern>
> >     </servlet-mapping>
>
> This is where I still don't understand what I'm supposed to do. My original
> goal (with the XML entries at the beginning of this mail) was to have all
> resources matching "*.class" (in any context within the application) mapped
> to the "invoker" servlet, just as all files matching "/servlet/*" are by
> default.
>

Is the intent to have the classes executed as servlets?  If so, you're going about it
the hard way -- people would need to use ".class" in the request URIs to trigger the
invoker to execute them (assuming you are messing with the ROOT context):

    http://localhost:8080/some/path/to/MyServlet.class

which doesn't sound like what you really want to do.

If you want to use some other prefix than "/servlet" to trigger general servlet
execution, one approach would be

    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/foo/*</url-pattern>
    </servlet-mapping>

Now, any request for

    http://localhost:8080/foo/MyServlet

will cause servlet class MyServlet.class (loaded from anywhere on the class path for
this web app, which includes the WEB-INF/classes and WEB-INF/lib/*.jar locations
automatically) to be executed.  Of course, the standard mapping is still there, so

    http://localhost:8080/servlet/MyServlet

will do the same thing.

>
> I was incorrect in stating last time that my .class files were being treated
> as static data - I must have mis-configured apache somewhere. I am now
> attempting to access a servlet directly through tomcat, and am getting the
> following 404 error:
>
>    "Not enough information /examples/Uptime.class null"
>
> (http://localhost:8080/examples/Uptime.class being the URL)
>
> I presume the reason for this is that the invoker servlet attempts to load
> the servlet from the WEB-INF/classes directory (as usual) - but there is
> none there. What I'm after is to have the .class file automatically loaded,
> examined, and executed (in some situations, this is desireable since you
> don't have to change the contents of WEB-INF to get a servlet to work). In
> other words, I'm looking for the "classic" one-servlet-per-file functionality.

>
> Is this possible with Tomcat (without writing your own servlet invoker that
> is)?
>

Sure -- the invoker servlet already does that for you on it's "/servlet/*" mapping.
You don't have to add anything at all for this, but you can add additional mappings for
the invoker if you want, as described above.

>
> Thank you,
>

Craig McClanahan



Re: Can I start servlets by extension or I need to change web.xml everytime.

Posted by Peter Schuller <pe...@infidyne.com>.
Hello,

[my attempted servlet mapping]
> >         <servlet-mapping>
> >             <servlet-name>
> >                 invoker
> >             </servlet-name>
> >             <url-pattern>
> >                 *.class
> >             </url-pattern>
> >         </servlet-mapping>
> >


> The basic source of information is the Servlet API Specification, version 2.2,
> which you can download from <http://java.sun.com/products/servlet/download.html>.
> Section 10 talks about how mappings work.

Ah. I didn't realize Tomcat (or rather, the Servlet framework) was
application centric nowadays. Thank you.

> Now, you let's assume that you have done this in a web application whose context
> path is "/myapp", and the complete URL to access this app is:
> 
>     http://localhost:8080/myapp
> 
> Now, you might use the following types of mappings:

[snip]
>     <!-- Process all GIF images myself, instead of
>         letting the default file-serving servlet serve them. -->
>     <servlet-mapping>
>         <servlet-name>myservlet</servlet-name>
>         <url-pattern>*.gif</url-pattern>
>     </servlet-mapping>

This is where I still don't understand what I'm supposed to do. My original
goal (with the XML entries at the beginning of this mail) was to have all
resources matching "*.class" (in any context within the application) mapped
to the "invoker" servlet, just as all files matching "/servlet/*" are by
default.

I was incorrect in stating last time that my .class files were being treated
as static data - I must have mis-configured apache somewhere. I am now
attempting to access a servlet directly through tomcat, and am getting the
following 404 error:

   "Not enough information /examples/Uptime.class null"
   
(http://localhost:8080/examples/Uptime.class being the URL)
   
I presume the reason for this is that the invoker servlet attempts to load
the servlet from the WEB-INF/classes directory (as usual) - but there is
none there. What I'm after is to have the .class file automatically loaded,
examined, and executed (in some situations, this is desireable since you
don't have to change the contents of WEB-INF to get a servlet to work). In
other words, I'm looking for the "classic" one-servlet-per-file functionality.

Is this possible with Tomcat (without writing your own servlet invoker that
is)?

Thank you,

-- 
/ Peter Schuller, InfiDyne Technologies HB

PGP userID: 0x5584BD98 or 'Peter Schuller <pe...@infidyne.com>'
Key retrival: Send an E-Mail to getpgpkey@scode.infidyne.com
E-Mail: peter.schuller@infidyne.com Web: http://scode.infidyne.com


Re: Can I start servlets by extension or I need to change web.xml everytime.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Peter Schuller wrote:

> > You can try making a generic mapping entry in web.xml
> >
> > <servlet-mapping>
> >       <servlet-name>
> >               whatever
> >       </servlet-name>
> >       <url-pattern>
> >             /whateverdirectory-eg-servlets/*
> >       </url-pattern>
> > </servlet-mapping>
>
> I'm not the one who asked the original question, but I am having the same
> problem. What exactly should one put there? I've done this:
>
>         <servlet-mapping>
>             <servlet-name>
>                 invoker
>             </servlet-name>
>             <url-pattern>
>                 *.class
>             </url-pattern>
>         </servlet-mapping>
>
> But .class files are still treated as static data.

> I'd love to RTFM, but I haven't found any FM yet :) Is there any documentation
> at this point (for Tomcat in general I mean)?
>

The basic source of information is the Servlet API Specification, version 2.2,
which you can download from <http://java.sun.com/products/servlet/download.html>.
Section 10 talks about how mappings work.

Briefly, you can map a servlet to handle requests of the following types:

- A specific URL path (relative to the context path of your web application).

- A set of URLs that start with a specific prefix (which often looks like a
  directory name when you use it in a URL).

- A filename extension (which is how JSP pages get recognized and
  compiled/executed instead of being displayed.

To illustrate these options, let's assume that you have defined a servlet in your
web application like this:

    <servlet>
        <servlet-name>myservlet</servlet-name>
        <servlet-class>com.mycompany.mypackage.MyServlet</servlet-class>
    </servlet>

Now, you let's assume that you have done this in a web application whose context
path is "/myapp", and the complete URL to access this app is:

    http://localhost:8080/myapp

Now, you might use the following types of mappings:

    <!-- Process http://localhost:8080/myapp/my/exact/path -->
    <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>/my/exact/path</url-pattern>
    </servlet-mapping>

    <!-- Process any URL that starts with
        http://localhost:8080/myapp/images/ -->
    <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>/images/*</url-pattern>
    </servlet-mapping>

    <!-- Process all GIF images myself, instead of
        letting the default file-serving servlet serve them. -->
    <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>*.gif</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>*.GIF</url-pattern>
    </servlet-mapping>

As the last example illustrates, mapping patterns are case sensitive.

In each case, the servlet container looks at the request URI, figures out which
defined mapping matches (the priority rules are described in the specification),
and therefore identifies the name of the desired servlet.  Next, it loads an
instance of that servlet (if it's not already loaded), and calls your service
method.

For more examples, look at the file "conf/web.xml" under the directory into which
you've loaded Tomcat.  These are the default mappings that are provided for all
web applications, unless you override them.  Note that the "invoker" servlet is
mapped to "/servlet/*", which is why those types of requests work -- the invoker
servlet grabs the servlet class name from the rest of the request, and calls it's
service() method.  In addition, the JSP page compiler servlet is mapped to the
"*.jsp" extension.

>
> Thank you,
>
> --
> / Peter Schuller, InfiDyne Technologies HB
>

Craig McClanahan



Re: Can I start servlets by extension or I need to change web.xml everytime.

Posted by Peter Schuller <pe...@infidyne.com>.
> You can try making a generic mapping entry in web.xml
> 
> <servlet-mapping>
> 	<servlet-name>
>       	whatever
> 	</servlet-name>
> 	<url-pattern>
>             /whateverdirectory-eg-servlets/*
> 	</url-pattern>
> </servlet-mapping>

I'm not the one who asked the original question, but I am having the same
problem. What exactly should one put there? I've done this:

	<servlet-mapping>
            <servlet-name>
	        invoker
	    </servlet-name>
	    <url-pattern>
	    	*.class
	    </url-pattern>
	</servlet-mapping>        

But .class files are still treated as static data.

I'd love to RTFM, but I haven't found any FM yet :) Is there any documentation
at this point (for Tomcat in general I mean)?

Thank you,

-- 
/ Peter Schuller, InfiDyne Technologies HB

PGP userID: 0x5584BD98 or 'Peter Schuller <pe...@infidyne.com>'
Key retrival: Send an E-Mail to getpgpkey@scode.infidyne.com
E-Mail: peter.schuller@infidyne.com Web: http://scode.infidyne.com


RE: Can I start servlets by extension or I need to change web.xml everytime.

Posted by Andrew Cathrow <ac...@seagull.nl>.
You can try making a generic mapping entry in web.xml

<servlet-mapping>
	<servlet-name>
      	whatever
	</servlet-name>
	<url-pattern>
            /whateverdirectory-eg-servlets/*
	</url-pattern>
</servlet-mapping>

Aic

-----Original Message-----
From: Alexey V. Meledin [mailto:avm@webclub.ru]
Sent: 08 April 2000 14:09
To: tomcat-user@jakarta.apache.org
Subject: Can I start servlets by extension or I need to change web.xml
everytime.


Hi!

  Anybody knows how to start servlets by extention?
  Users need a possibility to write and run their own servlets,
  without changing web.xml file and tomcat restart.

Alexey V. Meledin <av...@webclub.ru>
> InterForge Developers Group,  St-Petersburg, Russia
New: http://www.crossroad.ru; http://www.garoway.com
> > > > > > "InterForge to Forge Ahead" > > > > > > >



--------------------------------------------------------------------------
To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
For additional commmands, email: tomcat-user-help@jakarta.apache.org