Tomcat - access another context

J

Jay Parmar

I have two different context in Tomcat 4.

Now i want to access one of my bean which resides in one context from
another context.

for example,
one context is .......
\webapps\application1\my.jsp

seconde context is .......
\webapps\application2\WEB-INF\classes\test.class


now i want to call method of test class from my.jsp file.

Is it possible ?
if yes, how ?

Thanks in advance

Jay
 
C

Chris Smith

Jay said:
Now i want to access one of my bean which resides in one context from
another context.

for example,
one context is .......
\webapps\application1\my.jsp

seconde context is .......
\webapps\application2\WEB-INF\classes\test.class


now i want to call method of test class from my.jsp file.

It's not easily possible. Perhaps if you explained, from a higher
level, what you're trying to accomplish, I could make a better
suggestion about how to solve your problem.

In terms of brute force approaches, you could probably create a custom
URLClassLoader that could load the class from a different path, and then
call the method using reflection APIs. That's very ugly, but it could
work. It does require that you know the path of the other context,
though... you can't look it up from the servlet API.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
X

X_AWemner_X

I have two different context in Tomcat 4.
Now i want to access one of my bean which resides in one context from
another context.
for example,
one context is .......
\webapps\application1\my.jsp
seconde context is .......
\webapps\application2\WEB-INF\classes\test.class
now i want to call method of test class from my.jsp file.

Never tried this one but give it a shot.
Store bean reference to app1 context:
serveltContext.setAttribute("myGlobalBean", myBeanInstance) method.

Then in app2 get reference to an app1 context and read given attribute.

getServletContext().getContext("/application1").getAttribute("myGlobalBean")

I dont see any reason why this would not work. However, in Tomcat you _must_
enable crossContext attribute in app2.xml file.
<context path="/app2" docBase=.... crossContext="true">
</context>

Without giving grants to access another context you are able to use only
current servletContext. This parameter is a server implementation specific
issue. To enforce app1 initialization before app2 you must use autostartup
servlets where you may store global references.

Another way would be to use a global resource references where you access
through namingcontext (jndi). Tomcat has a very flexible way to init global
resource references.
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top