Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Tomcat - access another context

Reply
Thread Tools

Tomcat - access another context

 
 
Jay Parmar
Guest
Posts: n/a
 
      01-06-2004
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
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      01-06-2004
Jay Parmar wrote:
> 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
 
Reply With Quote
 
 
 
 
X_AWemner_X
Guest
Posts: n/a
 
      01-07-2004
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spring context refering to application context Jani Tiainen Java 3 08-27-2007 07:24 AM
return HttpStatusCode.ServiceUnavailable in the context.context.Response.StatusCode (Http response code 503) Flip Rayner ASP .Net 1 01-23-2007 06:35 AM
How to retrieve a session Bean in the Context in a class with the Context reference asd Java 1 11-09-2006 05:00 PM
Strange Context Error: Context 0x197ee0 is disconnected in VS 2005 =?Utf-8?B?U3VuU21pbGU=?= ASP .Net 0 01-10-2006 03:59 PM
Context.Items vs Context.Handler (passing values between pages) VS_NET_DEV ASP .Net 2 05-25-2004 01:16 PM



Advertisments