我已经将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:
感谢任何帮助。
答案 0 :(得分:2)
您直接访问JSP,而无需通过设置所有属性的servlet。很明显,当JSP执行时,所有属性都为空。
地址栏中的URL必须是servlet的URL,而不是JSP的URL。