File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing objects between 2 servlets

 
georgejk
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all..
I would like to clarify one doubt. I have one requirement to pass the file object which is created in one servlet to another servlet. But the probelm is, both these servlets are residing in different context path. So can anybody suggest an idea in which i can pass information from say servlet A to Servlet B.
Regards
George
 
Brian Nice
Ranch Hand
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the servlets are on the same application server, you can store the object in the application context. All servlets, JSPs have access to this area.
Brian
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In terms of security and separation of applications, this is a bad idea. The J2EE design of Servlet containers (and EJB containers) encourages them to be treated as completely separate applications, even though they may share the same JVM.
If you start sharing data between apps, you blur the edges between the applications. You can specify what data gets shared, but you can't decide who gets access to it.
If you are just doing this to share Servlets or access to a database, it is better to include the servlet in the other web app or make it read the data from the database itself rather than passing data between applications.
That said, you can reach from one context to another using getContext().getContext( new_context )
Have a look at javax.servlet.ServletContext to see the sort of things you can do from there, including reading and writing data to the other context. Notice that many of the methods are marked as Deprecated... with no direct replacement. This is an indication of the sort of security problems this behaviour has created.
The use of getContext( new_context ) is often poorly implemented anyway, and this should be reason enough to stay away.
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"georgejk",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic