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运行爬虫代码
    python语法之流程控制(if while for)
    python基本数据类型
    python基本运算符
    python用户交互与格式化输出
    jieba模块基本介绍
    wordcloud库基本介绍
    计算机基础之编程语言
    计算机基础
    python入门之流程控制
  • 原文地址:https://www.cnblogs.com/liunanjava/p/4269057.html
Copyright © 2011-2022 走看看