Querying the Servlet/JSP Engine

A

Albretch

How could you query the Servlet Container and/or ServletContext for
each webapp, in order to find out how many webapps and servlets are in
a webapp and to which URL's are they mapped?

I know for sure (after looking at the classloaders section of
tomcat's bootstrap class) it -could- be possible. Also the admin or
manager app do that.

If this is not possible from a published API, why do you think it is
not?
 
R

Ryan Stewart

Albretch said:
How could you query the Servlet Container and/or ServletContext for
each webapp, in order to find out how many webapps and servlets are in
a webapp and to which URL's are they mapped?

I know for sure (after looking at the classloaders section of
tomcat's bootstrap class) it -could- be possible. Also the admin or
manager app do that.

If this is not possible from a published API, why do you think it is
not?
A ServletContext is context relative (if you couldn't tell from the name).
It has no knowledge of any context but its own. You may find something if
you dig into the API of whatever container you're using, but the admin and
manager apps have nothing to do with it. They read and write XML files.
 
A

Albretch

Ryan Stewart said:
A ServletContext is context relative (if you couldn't tell from the name).
It has no knowledge of any context but its own. You may find something if
you dig into the API of whatever container you're using, but the admin and
manager apps have nothing to do with it. They read and write XML files.

Well, then in order to do it in a portable way, the web.xml webapp
descriptors will have to be parsed!

I need to pass a resource/common class to all servlets in a webapp.
THisis, I think, the way you could approach it in a portable way:

1._ In the Servlet Context Listener run some custom code to read the
descriptor and get this info.

2._ Try to find/read a copy (which should have been previously
persisted somewhere (FS or DBMS)) if not found DS should be produced.

3._ Set the needed info in the resource you will need to share with
all servlets belonging to the same webapp. It would then effectively
become kind of a 'singleton' for all webapps belonging to the same
servlet context.
 
R

Ryan Stewart

Albretch said:
"Ryan Stewart" <[email protected]> wrote in message

Well, then in order to do it in a portable way, the web.xml webapp
descriptors will have to be parsed!

I need to pass a resource/common class to all servlets in a webapp.
THisis, I think, the way you could approach it in a portable way:

1._ In the Servlet Context Listener run some custom code to read the
descriptor and get this info.

2._ Try to find/read a copy (which should have been previously
persisted somewhere (FS or DBMS)) if not found DS should be produced.

3._ Set the needed info in the resource you will need to share with
all servlets belonging to the same webapp. It would then effectively
become kind of a 'singleton' for all webapps belonging to the same
servlet context.
Now wait, you were talking about finding all webapps in a container. To make
some resource available to a number of servlets in a single webapp, you
simply use the ServletContext. Either set init params in web.xml or set
stuff up with a ServletContextListener.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top