我如何从 spring 网络流 xml 获取会话?
How can i get session from spring web flow xml?
我在操作 4 中阅读了 spring,但我感到困惑的是该示例没有显示如何从请求中获取会话。
我想实现一个完整的登录流程,我想从 jsp 获取会话以检查用户是否存在。
示例刚刚显示了这个 class 的 requestParameters?(我什至不知道它是什么)
并使用点 '.'从 Get 获取参数 method.But 我如何获取会话?
如果方法是 Post?
<action-state id="lookupCustomer">
<evaluate result="order.customer"
result-type="com.springinaction.pizza.domain.Customer"
expression="pizzaFlowActions.lookupCustomer(requestParameters.phoneNumber)" />
<transition to="registrationForm"
on-exception="com.springinaction.pizza.service.CustomerNotFoundException" />
<transition to="showOrder" />
</action-state>
我想你在谈论 spring MVC,Spring 用于你的应用程序中需要的 classes 的依赖注入。
i) 要将用户对象保持在会话中,请在控制器的参数中包含 HttpSession 对象 class,它应该是会话范围的,并将会话值存储在用户对象中。
例如:
@Scope("session")
@Controller
public class UserController {
@RequestMapping(method = RequestMethod.GET)
public String testMestod(HttpServletRequest request){
User user=(User)session.getAttribute("cart");
return "testJsp";
}
}
ii) 同时将用户对象 class 作为范围
的会话对象
例如:
@Scope("session")
public class User
{
String user;
/* setter getter*/
}
iii) 您可以拥有 XML 文件以进一步依赖 AOP 等
例如:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<bean id="user" class="com.User" scope="session">
<aop:scoped-proxy/>
</bean>
</beans>
我在操作 4 中阅读了 spring,但我感到困惑的是该示例没有显示如何从请求中获取会话。
我想实现一个完整的登录流程,我想从 jsp 获取会话以检查用户是否存在。
示例刚刚显示了这个 class 的 requestParameters?(我什至不知道它是什么)
并使用点 '.'从 Get 获取参数 method.But 我如何获取会话?
如果方法是 Post?
<action-state id="lookupCustomer">
<evaluate result="order.customer"
result-type="com.springinaction.pizza.domain.Customer"
expression="pizzaFlowActions.lookupCustomer(requestParameters.phoneNumber)" />
<transition to="registrationForm"
on-exception="com.springinaction.pizza.service.CustomerNotFoundException" />
<transition to="showOrder" />
</action-state>
我想你在谈论 spring MVC,Spring 用于你的应用程序中需要的 classes 的依赖注入。
i) 要将用户对象保持在会话中,请在控制器的参数中包含 HttpSession 对象 class,它应该是会话范围的,并将会话值存储在用户对象中。
例如:
@Scope("session")
@Controller
public class UserController {
@RequestMapping(method = RequestMethod.GET)
public String testMestod(HttpServletRequest request){
User user=(User)session.getAttribute("cart");
return "testJsp";
}
}
ii) 同时将用户对象 class 作为范围
的会话对象例如:
@Scope("session")
public class User
{
String user;
/* setter getter*/
}
iii) 您可以拥有 XML 文件以进一步依赖 AOP 等
例如:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<bean id="user" class="com.User" scope="session">
<aop:scoped-proxy/>
</bean>
</beans>