Tomcat - access another context

Discussion in 'Java' started by Jay Parmar, Jan 6, 2004.

  1. Jay Parmar

    Jay Parmar Guest

    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
     
    Jay Parmar, Jan 6, 2004
    #1
    1. Advertising

  2. Jay Parmar

    Chris Smith Guest

    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
     
    Chris Smith, Jan 6, 2004
    #2
    1. Advertising

  3. Jay Parmar

    X_AWemner_X Guest

    > 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.
     
    X_AWemner_X, Jan 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VS_NET_DEV
    Replies:
    2
    Views:
    3,827
    jenny
    May 25, 2004
  2. =?Utf-8?B?U3VuU21pbGU=?=
    Replies:
    0
    Views:
    715
    =?Utf-8?B?U3VuU21pbGU=?=
    Jan 10, 2006
  3. Flip Rayner
    Replies:
    1
    Views:
    702
    bruce barker
    Jan 23, 2007
  4. asd
    Replies:
    1
    Views:
    447
    www.pulpjava.com
    Nov 9, 2006
  5. After
    Replies:
    9
    Views:
    950
Loading...

Share This Page