0

こんにちは、私は春が初めてです。私のプロジェクトは spring+hibernate+jsp を扱っています。私は自分に与えられた仕事についてとても心配している

仕事:

JSPテキストボックスの値をセッションに保存したいのですが、ステップの後、スプリングコントローラーでそれを取得してデータベースプロセスを続行したいのですが...助けてください。

4

2 に答える 2

1

Spring プロジェクトを使用した 4 ステップの登録プロセスが必要な場合は、Spring Web Flow をご覧になることをお勧めします。サンプルはこちら、チュートリアルはこちら、stackoverflow と Web で検索できます。あなたが望むことを正確に行うために使用されます。

それ以外の場合は、@SessionAttributes をコントローラーに追加し、@ModelAttributes を宣言する必要があります。次に例を示します。

    @SessionAttributes({"oneDto","secondDto", [...as many as you want...]})
    public class MyController {

        [...Declaration and init of forms and modelAttributes...]

        @RequestMapping(method = RequestMethod.POST)
        public String processFirstPage(
            @ModelAttribute("oneDto") OneDto infoFromFirstPage,
            BindingResult result, SessionStatus status) {

                    [...Do whatever you need...]

            //return form success view
            return "secondPageView"; //uses secondDto

        }

        @RequestMapping(method = RequestMethod.POST)
        public String processSecondPage(
            @ModelAttribute("oneDto") OneDto infoFromFirstPage, @ModelAttribute("secondDto") SecondDto infoFromSecondPage
            BindingResult result, SessionStatus status) {

                    [...Do whatever you need...]

            //return form success view
            return "thirdPageView";

        }
    }

JSP の観点から、dto はフォームの「modelAttribute」で宣言され、すべてのフィールドは入力、選択などのパスにあります。

<form:form method="post" modelAttribute="oneDto" action="matchResquestMappingURL" enctype="application/x-www-form-urlencoded">
<form:input path="oneField"/> 
etc.

完全な TLD の説明はこちら

複数の DTO を使用する必要はありません。同じものを使用して、各ページにさらに情報を追加できます。データの使用が完了したら、 を呼び出しstatus.setComplete();てセッションを消去します。

これは概念を理解するための基礎にすぎませんが、これに対処する方法は他にもたくさんあります。たとえば、こちらで確認できます。(複数ページのフォーム)

于 2013-03-29T10:03:44.600 に答える
1

jsp で:

 <c:set var="name" value="yourname" scope="session"  />

春に

  ServletRequestAttributes attr = (ServletRequestAttributes)  
     RequestContextHolder.currentRequestAttributes();
   HttpSession session = attr.getRequest().getSession();
   session.getAttribute("name");
于 2013-03-28T13:03:53.117 に答える