• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling one another's context Servlet from other one

 
Baseet Ahmed
Ranch Hand
Posts: 225
Java Notepad Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Baseet Ahmed
Ranch Hand
Posts: 225
Java Notepad Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
Java Notepad Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
^^^
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic