1. 在jsp页面中JavaScript怎么能获取session中的变量?(最好能写条语句示范下,呵呵)2.                      session.setAttribute("type","jpg");
session.setAttribute("adsite_adid",adsite_adid[1]);
session.setAttribute("adsite_adpath",adsite_adpath[1]);
response.sendRedirect("adsite1.jsp");                                //第一次
try{
    Thread.sleep(1000);
                        }catch(Exception e){}
session.setAttribute("type","swf");
session.setAttribute("adsite_adid",adsite_adid[0]);
session.setAttribute("adsite_adpath",adsite_adpath[0]);
response.sendRedirect("adsite1.jsp");                                //第二次
    帮忙看下上面的代码,是不是不能两次重定位到一个jsp页面啊,如果要实现上面的功能应该怎么办啊?望高手指点,先谢谢了!

解决方案 »

  1.   

    javascript是不能和session交换数据的,实在要交换数据,可以用ajax
      

  2.   

    1.<%@page contentType="text/html" pageEncoding="UTF-8"%>
    <% request.setCharacterEncoding("UTF-8");%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd"><html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <%
            session.setAttribute("test", "你好");
            String s=(String)session.getAttribute("test");
            %>
            <script>
                var x="<%=s%>";
                alert(x);
            </script>
        </body>
    </html>
    2.
    怎么可能在一个页面中顺序执行"两次重定位到一个页面"啊...- -!
    如果你需要这样先重定向到A页面,再由A重定向到B
      

  3.   

    先把session中的变量值取出来放到页面上的hidden中,然后再用js 从hidden就可以取出来了对于两次重定向问题你最好判断一下
    在<head></head>之間加上   
      <%   
      out.println("<meta   http-equiv=\"refresh\"   content=\"0;url=my.jsp\">");   
      %>
    程序里要加上判断   
      if()   
      {   
      response.sendRedirect   
      }