2016-09-19 7 views
0


私はアクション4で春を読んでいますが、この例ではSessionをリクエストから取得する方法を示していないことがわかりました。
私は完全なログインフローを達成したい、私はjspからユーザーが存在するかどうか確認するセッションを取得したい。
この例では、このクラスのrequestParametersが表示されていますか?(私はそれが何であるか分かりません)
そしてポイント '。 Get method.Butからパラメータを取得するにはどうすればセッションを取得できますか?
メソッドが投稿の場合はいつですか?Spring Web Flow 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について話していると思います。春は、アプリケーションで必要なクラスの依存関係注入に使用されています。

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

あなたのコメントのために本当にありがとう、util私はまだHttpServletRequetからセッションを取得しますが、実際に私はこのフレームワークをSpring Web Flowについて話しています。私は設定ファイルでセッションを取得する方法がわからないという気がします。ユーザーのユーザー名 –

+0

このリンクはあなたに役立ちます: http://stackoverflow.com/questions/8913062/spring-webflow-how-to-pass-the-session-in-evaluate-expression –

+0

神様ありがとうございます! –

関連する問題