0

我创建了 servlet '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”应该显示在我的网页上,但我得到一个空白值。

下面是我对 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,而无需通过设置所有属性的 servlet。所以很明显,当JSP被执行时,所有的属性都是空的。

地址栏中的 URL 必须是 servlet 的 URL,而不是 JSP 的 URL。

于 2013-11-11T10:31:33.697 回答