• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to pass data between web applications?

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone comment on what is considered the proper way to pass data between web applications? I currently have an application containing a single web application. I would like to create a separate web application (in order to keep it modular and self-contained). However, I need to pass some data from the 1st web application to the 2nd because the 1st web app contains the logon function and has placed a user object in the session and also because I need some parameters to tell the 2nd web app what to do when it is invoked.
It is my understanding that the current specification requires separate HttpSession objects for each web app so that would seem to eliminate that method. I tried placing the necessary objects in the HttpRequest and performing a request.forward and, while that worked, it resulted in another problem. Namely, that the images in the 2nd web app do not display properly when its first page is displayed because the relative path is incorrect. Once I navigate past the first page in the 2nd web app the path is correct and the images display properly.
My current solution is to append the necessary data as parameters to the end of the URL and perform a response.sendRedirect. However, this would seem to be limiting for two reasons: 1) I can pass only Strings not Objects, e.g. my user object, this way, and 2) If I were to pass the user id and password as Strings, they would be "exposed".
Does anyone have a better solution?
Note: Although I am looking for a J2EE solution, I am using WebSphere Studio Application Developer v4.0.3 and WebSphere Application Server v4.0.3.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Web applications can communicate by:
1. URLConnection
2. Plain Socket connection
3. RMI
4. Java MessageService
5. JavaSpaces
6. Database
Data could be transferred as:
1. Plain text
2. XML
3. Serialized objects
4. byte array
(not an exhaustive list by any means)
Bill
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps I need to clarify my scenario. I have thought about temporarily storing data in a database but it seems like there should be an easier way. All I want to do is "hand off" control from a servlet in the 1st web app to a servlet in the 2nd web app. If I am able to do this (and I can) why can't I send some parameters "along for the ride"?
Ideally, I would like to just put my stuff in the request object and perform a forward. That does work. However, as I indicated, doing so causes a path problem when loading the images required by the 2nd web app's resultant JSP. It appears that when the 2nd web app's JSP loads, it is still referencing the 1st web app's path (because of the forward) and so the images are not found. If there is some way solve this problem, I would be happy.
However, as I indicated above, it seems, given the other alternatives, Sun would have provided a more straightforward method to do this. Or doesn't Sun think web apps would ever want to talk to one another?
[ October 09, 2002: Message edited by: Jay Damon ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun's main idea with the current servlet and JSP APIs is to enable web applications to be completely separate from each other. This makes it possible for you to just plug in a WAR file and fire it up without worrying about interactions with other web applications. Sun wants to encourage a market for "web applications" and this attention to security concerns is essential.
Are you sure you have separate web applications? (separate WEB-INF directories, etc) - I was under the impression that you could not do a forward between web applications since the request object should not be sharable.
Bill
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I have separate web apps (WARs). I am able to forward a request from the 1st web app to the 2nd web app with code similar to the following:
this.getServletConfig().getServletContext().getContext("/web/app/2nd").getRequestDispatcher("/nextservlet").forward(request, response);
Your response reaffirms my suspicions about Sun. It seems to me that they tend to think in terms of the theoretical and ideal world. Sometimes I wonder if those guys have ever written code in the real world or if they just sit in an ivory tower and dream this stuff up.
Don’t get me wrong. The idea of separate web apps is a good one. But in the real world, it is next to impossible to make applications COMPLETELY independent of one another. I, for example, do not want to make my users sign on to each individual web app. I want them to be able to perform a Single Sign On and my web apps share the necessary user data among themselves.
Currently, I have developed a working solution whereby I simply forward from the servlet in the 1st web app to the servlet in the 2nd web app and then, once it is there, redirect it to itself. This allows me to pass objects to the receiving servlet yet set the proper path so that the images to my JSP are found. However, one would think Sun would have provided a "cleaner" solution.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to say that the following just absolutely takes the cake.


Your response reaffirms my suspicions about Sun. It seems to me that they tend to think in terms of the theoretical and ideal world. Sometimes I wonder if those guys have ever written code in the real world or if they just sit in an ivory tower and dream this stuff up.


Let me suggest that if you have two "applications" that need to communicate user data, you may actually only have one "Web Application" in the sense it is commonly used in the Java community.
Bill
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going to use the logon to get the information from a database, you could store that in a session variable and call it from any page you want. You are correct in assuming that you will not be able to completely seperate the view from the code but you can minimize it to extreams. Each page will require to get something and each servlet will require you to set something. but to the programer, that is not important how it is set just how they can get the information.
 
This is my favorite show. And this is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic