Spring MVC session scoped bean Example in Examples of Spring 3.0 Examples
10258 Views
Hints
session scope beans are retains the memory of the object in user level. For each user or session access creates a instances and maintains the values of the bean in the application context for each user differently.
Step.1 Start a Web based Spring application
Select New menu -> Dynamic Web Project
Enter Project Name as "SessionScopeExample"
Click Next, Selecting Target runtime as Apache Tomcat 7.0
Click Next, Check Generate web.xml deployment descriptor then click on "Finish"
Copy and paste Spring's 21 Framework Jars, aopalliance-1.0.jar, aspectjtools-1.6.6.jar and commons-logging-1.1.jar into /WEB-INF/lib
Step. 2 Project Explorer Preview
RndHolder.java
package com.knowledgewalls;
public class RndHolder {
private int rndNumber;
public int getRndNumber(){
return rndNumber;
}
public void setRndNumber(int rndNumber){
this.rndNumber = rndNumber;
}
public void generateRndNumber(){
this.rndNumber = (int) (Math.random() * 99999);
}
}
Running URL: http://localhost:8089/SessionScopeExample/conn/ShowAccountDetails Hints: Session level bean maintains old random numbers too in the session level.