1

UserSignInController と PageNavigationController の 2 つのコントローラーがあります。両方のコントローラーで同じ HttpSession を維持したいのですが、差分ページに差分セッションが見つかりました。コントローラー ページに @SessionAttributes("userDetails") も追加しました。これを作成する方法を教えてください。 ?

UserSignInController

@RequestMapping(value="/analyzeinternet1.html", method=RequestMethod.GET)
    public ModelAndView getSocialMediaAdmin(HttpSession session, Model model) {
        LOG.info(" session..." + session);
        ModelAndView mv = null;

        UserProfile up = (UserProfile) session.getAttribute("userDetails");
        if(up == null) { //Checking whether the user is already signed up or not. If not, the user is redirected to login page. 
            LOG.info("No user in session...");
            mv = new ModelAndView("redirect:/login.html");
        } else {
            LOG.info("User in session..." + up);
            mv = new ModelAndView("internetanalyze");
            model.addAttribute("userDetails", up);
            session.setAttribute("userDetails", up);
            mv.addObject("clientId", up.getUserId());
        }

        LOG.info(mv);
        return mv;
    }

PageNavigationController

@RequestMapping(value="/analyzeinternet.html", method=RequestMethod.GET)
    public ModelAndView getAnalyzeInternet(HttpSession session, Model model) {
        LOG.info("-----session..." + session);
        //LOG.info("-----userprofile..." + userDetails);
        ModelAndView mv = null;
         up = (UserProfile) session.getAttribute("userDetails");
            LOG.info("User in session..." + up);
            mv = new ModelAndView("internetanalyze");
            //mv.addObject("clientId", up.getUserId());
            return mv;
    }

両方のセッション ID が異なり、私のリダイレクト コードは

<a href="<%=request.getContextPath()%>/analyzeinternet.html">
4

2 に答える 2

0

私は答えを見つけました。このコードは context.xml に記述されています

<Context path="/sm" docBase="sm"
        debug="5" reloadable="true" crossContext="true" cookies="false">

ここで、cookie="false" であり、cookie="true" である必要があります。

于 2013-03-19T11:36:44.683 に答える
0

あるページから 2 番目のページにアプリをブラウズし、2 番目のページが同じセッションを取得しない PageNavigationController を使用することを意味しますか? 同じセッションではないかどうかをどのように確認していますか? セッションで userDetails を設定してもよろしいですか?

また、リクエストでセッション Cookie が適切に渡されているかどうかも確認してください。firebug または chrome コンソールを使用して、応答と要求ヘッダーの Cookie 値を確認できます。

于 2013-03-18T06:44:52.253 に答える