• Post Reply Bookmark Topic Watch Topic
  • New Topic

data transfer bt war files??  RSS feed

 
Lilo Nguyen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have discovered that session info can't be transferred between war files even if the war files are within the same ear file, but why is it that the session ID is the same across all wars, but the data within is not? I know I can pass along data by storing info on filesystem, but would like to know the best practice for this situation. BTW, I am passing along the userid after I have authenticated the userid and pw with LDAP server by a regular JavaBean, and I am using oc4j production release 2. I know I have been very brief with this, but, hopefully, I have provided sufficient info to get feedback.
Thank you,
Lilo
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A WAR file is just for deploying your components
to containers in a standardized manner.
Assuming a HTTP server, you store session info
on the client, in the memory of the web container,
or some sort of persistent store.
 
Lilo Nguyen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rufus Bugleweed:
A WAR file is just for deploying your components
to containers in a standardized manner.
Assuming a HTTP server, you store session info
on the client, in the memory of the web container,
or some sort of persistent store.

Hi Rufus,
Thank you for your reply. I am storing the information in the HTTP session (session.setAttribute) so I think I am doing what you are saying already, although, I am not really sure what you are saying, but just for clarification on the above issue..here is an example I have tried......
War #1 file (test1.jsp which is in testing1-web.war):
<%@ page import="TestBean" %>
<jsp:useBean id="test" scope="session" class="TestBean" />
<html><body>
<jsp:setProperty name="test" property="userid" value="jlott1" />
<jsp:getProperty name="test" property="userid" /><br>
<%=session.getId()%><br>
<%
session.setAttribute("var1","joy");
String var1=(String)session.getAttribute("var1");
%>
THE SESSION VAR: <%=var1%><br>
<a href="../test2/test2.jsp">test2</a>
</body></html>
War #2 file (test2.jsp which is in testing2-web.war):
<%@ page import="TestBean" %>
<jsp:useBean id="test" scope="session" class="TestBean" />
<html><body>
HERE IT IS: <jsp:getProperty name="test" property="userid" /><br>
<%=session.getId()%><br>
<%
String var1=(String)session.getAttribute("var1");
%>
THE SESSION VAR: <%=var1%><br>
</body></html>
Both wars have the same bean in their respective WEB-INF/classes directory called TestBean (the class is Serializable because we plan to cluster):
import java.io.*;
public class TestBean implements Serializable
{
String uid;
public TestBean() {
}//end constructor
public String getuserid()
{
return uid;
}
public void setuserid( String s)
{
uid= s;
}
}//end class

And, the output from test1.jsp...
jlott1
c1a536d39ef644d295c9aca33b9778fa
THE SESSION VAR: joy
test2
output from test2.jsp...
HERE IT IS: null
c1a536d39ef644d295c9aca33b9778fa
THE SESSION VAR: null
so I guess it would make sense that if both TestBean classes within the two directories are instantiated then the info would not carry over because I would be looking in a different bean when I called test2.jsp (not exactly sure how this works (the bean instantiation) behind the scenes but would like to know if someone would like to explain it to me!!!), but it still doesn't make sense that if I am setting and getting an attribute within the same session ID (thus the same session....right?), why is the info lost? And, I have tried to make the bean global by putting it in the lib directory of the server; therefore, one instantiation, but it still doesn't work. And also, within my config files:
http-web-site.xml
<web-app application="default" name="testing123" root="/test1" shared="true"/>
<web-app application="default" name="testing321" root="/test2" shared="true"/>
application.xml
<web-module id="testing123" path="../applications/testing1-web.war" />
<web-module id="testing321" path="../applications/testing2-web.war" />
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you change
<jsp:useBean id="test" scope="session" class="TestBean" />
to
<jsp:useBean id="test" scope="application" class="TestBean" />
 
Lilo Nguyen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rufus Bugleweed:
What happens if you change
<jsp:useBean id="test" scope="session" class="TestBean" />
to
<jsp:useBean id="test" scope="application" class="TestBean" />

same thing...null...doesn't get passed along. But with application scope, wouldn't the bean object be alive as long as the server is up and running so that is not really what I want because I want the userid in the bean object only after they have been authenticated and until their session dies (close browser, etc.). I want the bean cleaned up after such...there is no reason to have that persistent object out there. I did try putting the bean in the global lib directory of the server. I deleted the WEB-INF/classes bean class files from both war files and added it to the global server lib directory, restarted server...with no luck. I !think! I have read where it is standard for a session not to be passed between wars, but it just doesn't make sense that the sessionid is the same....I just want an explanation or reasoning behind this. Why also can I not get wars to share information that are within the same ear file? I can't get an answer on Oracle's forum so I thought I would try out here. Thanks, Lilo
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!