我创建了 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:
任何帮助表示赞赏。