Hi Tomas,
AFAIK, you can't do what you want to do, as sessions are not shared
between different applications.
When you try...
disp=context.getRequestDispatcher("/app2/app2.jsp");
disp.forward(request,response);
from inside your "app1" application, you are really forwarding to
"/app1/app2/app2.jsp", hence the 404 not found. And when you try
sendRedirect(), you are asking the BROWSER to issue a call to the second
page, and the browser knows nothing about server side sessions so that's
why your attribute doesn't get through.
Unless both jsp pertain to the same application, I don't know of any
standard way of directly sharing objects between webapps. You might have
to use something external. I guess the philosophy behind that is "if
they have to share, they should be part of the same webapp" which can be
seen, IMO, as a security feature and a limitation.
As a non standard way of doing it, you might be able to use the "parent"
attribute in the orion server.xml configuration
(http://www.orionserver.com/docs/server.xml.html), but I'm not sure it
allows you to do what you want to, as I have never used it.
Does anyone know if there is a standard solution for this?
regards,
Dan
Tomas Anderson wrote:
>
> Hello.
> I hope someone can help me with this basic question.
>
> I have 2 separate applications, app1 and app2. One jsp
> and one servlet in each.
> From the jsp I send some parameters to the servlet. I
> prosess them and put the answer in a session variable
> like this:
>
> servlet1.java:
> String strP1 = request.getParameter("param1");
> String strP2 = request.getParameter("param2");
>
> ... procsess them
> String strAnswer = strP1 + strP2;
>
> Get the session.
> session = request.getSession(true);
> Put a session variable.
> session.setAttribute("result", strAnswer);
> ...
>
> Now I want to send the session to the other
> application, app2, where the jsp file reads the
> session variable and displays it.
>
> jsp2.jsp:
> <%
> String str = (String)session.getAttribute("result");
> out.println("result: " + str);
> %>
>
> I have put shared="true" in both web-app tags.
> <web-app application="App1" name="App1-web"
> root="/app1" shared="true" />
> <web-app application="App2" name="App2-web"
> root="/app2" shared="true" />
>
> Ok. If I do in sevlet1.java:
>
> disp=context.getRequestDispatcher("/app2/app2.jsp");
> disp.forward(request,response);
>
> I get a: 404 Not Found...............
>
> If I use sendRedirect(..,..) the session is not
> shared, it is empty.
>
> How can I connect the 2 applications? Did I miss andy
> configuration setting? And how to send the session to
> the other application. It seem setting shared=true
> means something else than I thought.
>
> Greatfull for any hint.
> Tomas