2016-09-19 1 views
0


나는 행동 4에서 봄을 읽었지 만, 예제가 Session에서 요청을 얻는 방법을 보여주지 않았다는 것을 혼란스러워했다.
나는 완전한 로그인 흐름을 원한다. 사용자가 존재하는지 확인하기 위해 jsp에서 세션을 가져오고 싶다.
예제에서 requestParameters가이 클래스를 나타 냈습니까? (심지어 무엇인지 모릅니다)
그리고 '.' Get method.But에서 매개 변수를 가져 오려면 어떻게해야합니까?
메소드가 게시 일 경우 언제입니까?스프링 웹 플로우 XML에서 세션을 가져 오는 방법은 무엇입니까?

<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> 
+0

한마디로 말하면, 나는 단지 흐름에서 세션을 얻고 싶습니다. 로그인 한 사용자는 세션에 사용자 정보가 저장 될 것입니다. 다음 플로우를 계속 진행할 수있게하려고합니다. –

답변

1

여러분은 스프링 MVC에 대해 이야기하고 있으며 Spring은 애플리케이션에 필요한 클래스의 종속성 주입에 사용된다고 생각합니다.

i) 세션에서 사용자 개체를 유지하려면 세션 범위가되어야하는 컨트롤러 클래스의 매개 변수에 HttpSession 개체를 갖고 사용자 개체에 세션 값을 저장하십시오.

 @Scope("session") 
    @Controller 
    public class UserController { 
    @RequestMapping(method = RequestMethod.GET) 
    public String testMestod(HttpServletRequest request){ 
    User user=(User)session.getAttribute("cart"); 
    return "testJsp"; 
    } 
    } 

II) 또한 예를 들어 범위

에 의해 세션 객체와 사용자 개체 클래스를 만들 : 예를 들어

 @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> 
+0

정말 당신의 의견을 주셔서 감사합니다, 지금은 여전히 ​​HttpServletRequet에서 세션을 얻을 util,하지만 실제로 봄 웹 흐름이 프레임 워크에 대해 이야기하고, 난 정말 그 설정 파일에 세션을 얻는 방법을 모르겠다 화가 느낌. 나는 사용자의 사용자 이름 –

+0

이 링크는 도움이 될 수 있습니다 : http://stackoverflow.com/questions/8913062/spring-webflow-how-to-pass-the-session-in-evaluate-expression –

+0

고맙습니다. –