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("要跳转的页面地址");
  • 相关阅读:
    【折腾】Docker官网下载Docker实在太慢怎么破!!!!!windows 安装docker
    centos7搭建FTP文件服务器--虚拟用户
    AWK简单案例
    SaltStack系统初始化
    ReactNative环境搭配及软件安装
    extundelete工具恢复误删文件
    linux磁盘阵列raid1的搭建教程
    linux中Raid0磁盘阵列的搭建
    子网掩码的计算方法
    linux网络管理命令
  • 原文地址:https://www.cnblogs.com/liunanjava/p/4269057.html
Copyright © 2011-2022 走看看