页面跳转时参数携带与参数接收的几种方式

1.js中页面跳转

[javascript] view plain copy
 
  1. location.href = path + "/weixin/jsp/submitNewSuccess.jsp?package_number="+package_number  


参数接收方式:

[html] view plain copy
 
  1. <script type="text/javascript">  
  2.     var package_number = "<%=request.getParameter("package_number")%>";  
  3. </script>  

2.java代码中页面重定向

[java] view plain copy
 
  1. request.setAttribute("openid", openid);  
[java] view plain copy
 
  1. request.getRequestDispatcher("/weixin/jsp/weixinLogin.jsp").forward(request, response);  

页面中参数接收方式:

[html] view plain copy
 
  1. var openid =  "<%=request.getAttribute("openid")%>";  

把参数在java代码里面放到session里面:

[java] view plain copy
 
  1. request.getSession().setAttribute("openid", openId());  

页面中接收参数的方式:

[html] view plain copy
 
    1. <script type="text/javascript">  
    2.     var openid =  "<%=request.getSession().getAttribute("openid")%>";  
    3. </script>