Hi Barbara,
On 9/6/06, bkrausz <bkrausz(a)web.de> wrote:
Hi,
I try to save a Java- object to the context with groovy:
<%
test=context.getContext().get("test");
if(test==null)
println "test is null"
else
println "test is not null"
context.getContext().put("test",new Object());
%>
If you reload the page the object should be in the context and the output
should be "test is not null". But unfortunately I get "test is null".
No it's normal. :-)
I also tried it with the Servlet-Context like this:
<%
scontext=context.getRequest().getSession().getServletContext();
test=scontext.get("test");
if(test==null)
println "test is null"
else
println "test is not null"
scontext.put("test",new Object())
%>
Then I get an exception: java.lang.NoClassDefFoundError:
org/apache/catalina/session/StandardSessionFacade
This class is in the catalina.jar which is located in tomcat/server/lib and
the documentation of tomcat says: These classes and resources are TOTALLY
invisible to web applications.
I copied catalina.jar to WEB-INF/lib but then I get a ClassCastException:
java.lang.ClassCastException:
org.apache.catalina.session.StandardSessionFacade
I guess this is because of different ClassLoaders.
How can I save a Java-Object to a session?
And here is the code fixed :
<%
scontext=context.getRequest().getSession().getServletContext();
test=scontext.getAttribute("test");
if(test==null)
println "test is null"
else
println "test is not null"
scontext.setAttribute("test",new Object())
%>
jeremi
--
jeremi