aspose file tools*
The moose likes Servlets and the fly likes Calling one another's context Servlet from other one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling one another Watch "Calling one another New topic
Author

Calling one another's context Servlet from other one

Baseet Ahmed
Ranch Hand

Joined: Dec 18, 2006
Posts: 224
All,

We are having two diferrent web application(Servlet/JSP based) on one application server.
We want to integrate both application.

User will login through first application(say A).
He will be provided with one menu option for calling another web application(say B).
We want to know that how can we call the other servlet of another context from the application B's Servlet ?



Regards
Baseet Ahmed
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Look at the HttpServlet.getServletContext(String) method.

One thing to keep in mind is that the servlet spec does not go into great detail about cross context communication so the behavior across different containers will be, at best, inconsistent. Security conscious containers disable this feature by default so you'll need to check with the documentation for your container and do some experimenting to see exactly how things will work.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Baseet Ahmed
Ranch Hand

Joined: Dec 18, 2006
Posts: 224
Thank you for reply.

Can you provide some code snippet for demonstrating the same.

It would be useful for me to understand it more clearly.

What about response.sendRedirect method.

Will it work in our case, as we are having two different databases for the above two applications on the same machine.

Let's understand what we want:
Login through App A -> Works on App A -> Go to App B from App A -> Do work on App B -> return back to App A.

Both Application A, and B are having two different contexts in terms of Servlet/JSP tech.


Regards
Baseet Ahmed

^^^
There is substitute for papers,but none for Trees. Save Trees.
^^^
Abdul Kader
Ranch Hand

Joined: Apr 11, 2007
Posts: 115
See you can use response.sendRedirect(), however if you use that your request, response and session object will be deleted, and it will also visible to the end user that you are redirecting to another website. I have few thoughts which I like to share.

1. We can serialize the user object and send it across to another servlet which read (desterilize) this and created a session inn that 2 Server.

2. We can create a table which has to share by the 2 application and we can allow the user who has a valid session with respect to the both application. A new entry has to created when ever new user object was added and that entry has to be deleted when the user session expiries. Using Session listeners we can achieve this very easy... (Hope so)


Please share your thoughts if my assumption is wrong....
Baseet Ahmed
Ranch Hand

Joined: Dec 18, 2006
Posts: 224
Assalam alekum Mohammed Yousuff,

Agreed with your suggestion.

Rigth now,we want to do the activity of app B via login through app A.
Hence no need of session/request data of app A at present.

In case if require,we will see your points.

But one thing I want to ask, how to acheive the session management of users logged in,using Session listeners, which you are saying ver easy.

Thank you.
Regards
Baseet Ahmed

^^^
There is substitute for papers,but none for Trees. Save Trees.
^^^
 
jQuery in Action, 2nd edition
 
subject: Calling one another's context Servlet from other one