This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Two Web App communicating problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Two Web App communicating problem" Watch "Two Web App communicating problem" New topic
Author

Two Web App communicating problem

Garg Divya
Greenhorn

Joined: Feb 18, 2010
Posts: 8
Hi All,

Here i am using Apache Tomcat 6.0.16. I have 2 Web App Hello1 and Hello2 each having 2 servlet. The relevent content of first servlet is:



And for secondnd servet is:



I had put load on start up value 1 and 2 for both servlets repectively. Here is relevent content of server.xml



And here is output consol:



Now please can anybody help me in finding out the reason of why i am not getting the context of first app(Hello1) in second app(Hello2)


This is 2ndservlet
This is First contextnull


It is coming as null. Any suggestion most welcome. Thanks in advance.

Regards
Divya garg.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Divyyyyy please check your private messages for some administrative matter...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
From the javadocs of ServletContext.getContext:
In a security conscious environment, the servlet container may return null for a given URL.


In Tomcat you can get around this by setting the Context's crossContext attribute to true.


Ping & DNS - updated with new look and Ping home screen widget
Garg Divya
Greenhorn

Joined: Feb 18, 2010
Posts: 8
Hi,

Thanks for your reply. It was quite helpful. But my requirement is little changed now. Using Servlet context i can not get the session synchronization between two app because of some security issues. Please can you suggest me the best way of getting session synchronization between two app.

Thanks,
Divya Garg


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
What do you mean by "session synchronization"?
Garg Divya
Greenhorn

Joined: Feb 18, 2010
Posts: 8
ok let me elaborate.

I have a link in my page. As i click on that link my application get an attribute from from other app running on same server. But that attribute is set on application level on other application. so now the problem is if a user(same session) try to access my application on different timing, he will get different value of attribute because that attribute is dynamic with time. But i want a unique value for a user.

So now i have decided that i will use a Map or Hashtable to store a session id as key and attribute as value. So that every user would get a unique attribute. This is my idea. Can you suggest me is there any drawback in my approach related to seurity or performance something.

Thanks,
Divya garg
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
So there will be one value for each user, and that value should be unique across different web apps running on the same server? Where does this value come from, and how often does it change? Could it be stored in the DB along with all the other user information, so that all web apps can get at it?
Garg Divya
Greenhorn

Joined: Feb 18, 2010
Posts: 8
Yes there will be a unique for every user, this is primary requirement and that value will be like timestamps which will change every second. It will finally be stored in database.

Thanks,
Divya Garg
Garg Divya
Greenhorn

Joined: Feb 18, 2010
Posts: 8
Hi,

Sorry for late reply. Actually today i have discussed things with my PM. My task is little extended. I can not work on session ids. What i have to perform now is if a user log in from another browser then he or she should be in same session as he was in previous browser on the same application.

I mean to say is that a user is access the page and that page have an attribute value which is dynamic with time. Now problem is if the same user access the same page(after some time) by typing URL path of that page on different browser then he should be getting the same attribute value as it was previously.

By default we we log in our application from another browser then it logged in other session. So is there any technique to perform it?. Any suggestion regarding this? Thanks in advance.

Regards,
Divya Garg
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
Sounds like you will have to implement your own "session" object that tracks the user state. Make it serializable and write it to a common file space or database using the user's unique key.

Bill

Java Resources at www.wbrogden.com
Garg Divya
Greenhorn

Joined: Feb 18, 2010
Posts: 8
Hi all,

Thanks to all for your reply. My previous task is finished. Now my task is little more extended. Now i have been instructed that one of my application is deployed on one machine and i have to access its context in another app deployed on another server. So i think now i will have to use JNDI.

Since i had done some work on EJB with JBoss where we use JNDI and we bind HomeInterface to JNDI logical name and by that name we access that Home Interface in the code.

Here is that JNDI Code:





Here we can give the ip(in place of localhost) of web server.

In the same way now i will have to bind the servlet context of on application to JNDI Logical name. And through that name i will access the servlet context in another app deployed on another server. But now the problem is I m not getting sufficient coding based help from anywhere. Please can anybody provide me any of type help on this topic. Thanks in advance.

Regards,
Divya Garg
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Out of curiosity..
Why are you spreading things out over multiple web applications?

This is one area where the servlet spec (I haven't finished the spec for 3.0 so this might have changed) is not very specific.
Not specific means that behavior tends to be different from app server to app server, meaning that your app is not going to be very portable.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two Web App communicating problem
 
Similar Threads
action mapped error
New totally to things like tomcat
servlet programming problem in Eclipse
Beginner tutorial fail
New Windows Install of Eclipse 3.3.2, Tomcat 6.0.16, & Plugin