jsp1 页面中有如下代码  String PageFlag=request.getParameter("PageFlag");
  if(PageFlag!=null){
   if(PageFlag.equals("1")){
     out.print("传回来的reason:"+session.getAttribute("returnReason").toString()+"<BR>");
   }
  }else{
     out.print("奇怪<BR>");
  }
<html>
 <textarea name="reason" style="width=395px; height=88px"></textarea>
</html>jsp2 页面中有如下代码    String PageFlag = "1";
    String  reason = "很奇怪";
    session.setAttribute("returnReason",reason); 
问题:
  我运行jsp1之后到jsp2
 在jsp2中返回jsp1 传给jsp1一个PageFlag,一个session,
传回后 PageFlag的值确定为“1 ”,但是却进不到if(PageFlag.equals("1"))中而且连else内的内容也不执行!??也就是说 jsp1页面初始化的时候上面显示“奇怪“ 当跳转到jsp2从jsp2中获得PageFlag和session后再转回jsp1页面时,页面上什么也不显示。 还有更奇怪的就是session
  我明明没有把session.getAttribute("returnReason").toString()地值付给textarea,可当返回jsp1页面时textarea内却有session值!!!!??

解决方案 »

  1.   

    你如何访问jsp1的?确信是jsp1.jsp?PageFlag=1
      

  2.   


    在 js2中用response.sendRedirect("jsp1.jsp?PageFlag=1");返回去的,就算返回的不是1 至少也应该进到else里阿!!
      

  3.   

    如果不是1的话,你的else是不一定执行的,你的else是和if(PageFlag!=null){
    这句匹配的
      

  4.   

    String PageFlag=request.getParameter("PageFlag");
      if(PageFlag!=null){
           if(PageFlag.equals("1")){
             out.print("传回来的reason:"+session.getAttribute("returnReason").toString()+"<BR>");
           }
      }else{
         out.print("奇怪<BR>");
      }你这里的else是 PageFlag!=null 的else
    不是PageFlag.equals("1") 的...
    出现这个问题的原因就是因为 你PageFlag 有值!但不是"1"不是1有可能是因为有空格什么的
      

  5.   


    我刚刚也发现这点了 就把代码改成out.println("页面标示:"+PageFlag+"<BR>");
    if(PageFlag!=null){
       if(PageFlag.equals("1")){
       out.print("传回来的reason:"+session.getAttribute("returnReason").toString()+"<BR>");
     }else{
       out.print("为什么阿 !");
     }
    }else{
     out.print("奇怪<BR>");
    }这次 jsp1页面初始化时显示页面标示:null
    奇怪当再次返回时jsp1显示页面标示:1
      

  6.   


      String PageFlag=request.getParameter("PageFlag");
    -------------------------------------------------------------------
      out.print(PageFlag);//写上这个看看结果不就完了么!还用发帖问么!
      out.print(session.getAttribute("returnReason").toString());
    ---------------------------------------------------------------
      if(PageFlag!=null){
       if(PageFlag.equals("1")){
         out.print("传回来的reason:"+session.getAttribute("returnReason").toString()+"<BR>");
       }
      }else{
         out.print("奇怪<BR>");
      }
    <html>
     <textarea name="reason" style="width=395px; height=88px"></textarea>
    </html>
      

  7.   

    这样写试下吧:
    String PageFlag=request.getParameter("PageFlag")==null?"":request.getParameter("PageFlag");
      if(!PageFlag.equals("")){
       if(PageFlag.equals("1")){
         out.print("传回来的reason:"+session.getAttribute("returnReason").toString()+"<BR>");
       }
      }else{
         out.print("奇怪<BR>");
      }
    <html>
     <textarea name="reason" style="width=395px; height=88px"></textarea>
    </html>