zoukankan      html  css  js  c++  java
  • JSP 页面传值

     使用session会话传值并重定向页面

     //得到用户提交的值
     String name = request.getParameter("username");
     String pwd = request.getParameter("password");
     //创建HttpSessio对象
     HttpSession s = request.getSession();
     //将值绑定在session会话中
     s.setAttribute("Sname",name);
     s.setAttribute("Spwd",pwd);
     //重定向
     response.sendRedirect("yinyu.jsp");
    

    在yinyu.jsp页面中得到值

    //使用session会话取值
    String username = (String)session.getAttribute("Sname");
     String password = (String)session.getAttribute("Spwd");
    或者
    ${Sname}; ${Spwd};

     使用request方式传值并页面转发

     //得到用户提交的值
     String name = request.getParameter("username");
     String pwd = request.getParameter("password");
     //将值绑定在request中
     request.setAttribute("Rname",name);
     request.setAttribute("Rpwd",pwd);
     //页面转发
     RequestDispatcher rd = request.getRequestDispatcher("yinyu.jsp");
     rd.forward(request,response);

    在yinyu.jsp页面中得到值

     //使用request协助相关取值
    String username = (String)request.getAttribute("Rname");
     String password = (String)request.getAttribute("Rpwd");
    或者

    ${Sname};
     ${Spwd};

    setAttribute() 设置绑定属性值setAttribute("自定义命名",要绑定的引用);
    getAttribute() 取出得到属性值getAttribute("setAttribute中的自定义命名");
    sendRedirect() 重定向跳转页面sendRedirect("要跳转的页面地址");
  • 相关阅读:
    美国保健品排行榜
    美国海淘购物入门
    美国保健品品牌介绍之Now Foods
    haitaolab.com 我的新网站,欢迎访问
    PTC点击网赚入门
    信用卡基础知识
    12月购物10%-12%积分返还
    java界面设计(swing)
    c语言中阶乘的精确值
    java中Map集合的理解
  • 原文地址:https://www.cnblogs.com/liunanjava/p/4269057.html
Copyright © 2011-2022 走看看