0

サーブレット「SetAttributes」を次のように作成しました。

request.setAttribute("a1","v1");
HttpSession session=request.getSession();
session.setAttribute("a2","v2");
ServletContext application=getServletContext();
application.setAttribute("a3","v3");
request.setAttribute("c","request");
session.setAttribute("c","session");
application.setAttribute("c","application");

RequestDispatcher rd=request.getRequestDispatcher("Process.jsp");
rd.forward(request, response);

Process.jsp は次のようになります。

a1, a2, a3 can be directly accessed as: ${a1} ${a2} ${a3}<br />

        Each attribute can also be accessed as: ${requestScope.a1} ${sessionScope.a2} ${applicationScope.a3}<br />

        Accessing the repeated attribute directly then the value will be for: ${c}<br />
        Common attribute can also be accessed as: ${requestScope.c} ${sessionScope.c} ${applicationScope.c}<br />

        Trying to access out of scope attribute we get: ${applicationScope.a1}

'a1'、'a2'、'a3' などの属性の値が Web ページに表示されるはずですが、空白の値が表示されます。

以下は、Process.jsp の私の出力です。

a1, a2, a3 can be directly accessed as: 
Each attribute can also be accessed as: 
Accessing the repeated attribute directly then the value will be for: Common attribute can also be accessed as: 
Trying to access out of scope attribute we get:

どんな助けでも大歓迎です。

4

1 に答える 1

2

すべての属性を設定するサーブレットを経由せずに、JSP を直接ヒットしています。したがって、明らかに、JSP が実行されると、すべての属性が null になります。

アドレス バーの URL は、JSP の URL ではなく、サーブレットの URL である必要があります。

于 2013-11-11T10:31:33.697 に答える