我使用SpringSession + redis,它可以将会话保存到redis,但是当我在jsp中调用“$ {sessionScope.user.name}”时我无法获得会话属性
这是web.xml
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这是applicationContext.xml
<!-- spring data redis -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="localhost"/>
<property name="port" value="6379"></property>
<property name="password" value="123456"></property>
<property name="database" value="0"></property>
<property name="usePool" value="true"></property>
</bean>
<bean class="org.springframework.data.redis.core.RedisTemplate" id="redisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>
<!-- spring session -->
<context:annotation-config/>
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/>
这是控制器:
@RequestMapping("/login")
public String login(String name, String pwd,HttpSession session){
User user=new User();
user.setName(name);
user.setPwd(pwd);
session.setAttribute("user",user);
return "forward:/success.jsp";
}
@RequestMapping("test")
public String test(HttpSession session){
//there,session.getAttribute("user")=null ???
return "forward:/test.jsp";
}
当我请求项目时,我可以看到会话已保存在Redis中 enter image description here
但是当我请求test.action时,它无法获得Seesion属性。 怎么了?