使用pageConetxt.getattribute获得来自pageContxet.setattribute的值的问题。花了很多时间

来源:互联网 发布:淘宝拍下返现送小礼物 编辑:程序博客网 时间:2024/05/17 00:56

 文件的名称

      

 开始是只在pageContent.setAttribute()中设置scope

            

     <body>    <% pageContext.setAttribute("ting", "lover",pageContext.APPLICATION_SCOPE); %>    <jsp:forward page="MyJsp2.jsp"></jsp:forward>  </body>
<pre name="code" class="html"><body>    <% pageContext.setAttribute("ting", "lover"); %>    <jsp:forward page="MyJsp2.jsp"></jsp:forward>  </body>

   没有在pageContent.getAttribute()中设置scope

   <body>    <%=pageContext.getAttribute("ting") %>  </body>
结果显示是null

   


  不管你在setAttribute里怎么设置,甚至不设置只要在getAttribute中设置Scope就好了

     MyJsp.jsp代码

 

 <body>    <% pageContext.setAttribute("ting", "lover"); %>    <jsp:forward page="MyJsp2.jsp"></jsp:forward>  </body>

     MyJsp2.jsp代码

 <body>    <%=pageContext.getAttribute("ting",pageContext.APPLICATION_SCOPE) %>  </body>



0 0