Hi
I'm new to JSP and am having a right battle with session scope. Here's what I'm doing:
I have created a class with some variables and methods. As I want to be able to access the contents of my created object in other pages, I have instanciated my class into the session scope. Now, accessing / setting the variable parts of my session object is fine, no problems. However, I cannot seem to run the methods with in it. Here's an example of what I'm attempting:
<html>
<head>
</head>
<body>
<%!
public class testClass
{
//my variable
public String name;
//my method for updating my variable
public void updateName()
{
name="Bill";
}
}
%>
<%
//create a new object in session
session.setAttribute("sessionMyObject", new testClass());
//attempt to run the updateName method in the session object and set 'name' to Bill
session.getAttribute("sessionMyObject.updateName()");
//Display 'name' variable in the session object
out.print("Name value in session object: "+ session.getAttribute("sessionMyObject.name"));
%><br/><%
//accessing the specific variable (and not the methods) DOES work:
session.setAttribute("sessionMyObject.name", "Lee");
out.print("Name value in session object: "+ session.getAttribute("sessionMyObject.name"));
session.invalidate();
%>
</body>
</html>
This runs without any grumbling but the outcome is as follows:
Name value in session object: null
Name value in session object: Lee
Is it because I'm not calling the session object's method correctly, or is it because you cannot achieve what it is I'm trying to do?
Any ideas, as it's driving me mad!
Thanks in advance,
Lee