zoukankan      html  css  js  c++  java
  • JAVA-JSP内置对象之request范围

     

    相关资料:
    《21天学通Java Web开发》

     

    request范围
    1.在一次请求内有效。
    2.如果页面从一个页面跳转到另一个页面,那么属性就失效了。
    3.如果使用服务器端跳转<jsp:forward>,则属性仍然有效。
    4.通过使用request的setAttribute()方法来设置属性,并通过request的getAttribute()。

    requestdemo.jsp(用户跳转)

     1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>request范围</title>
     5 </head>
     6 <body>
     7   <%--在request 范围设置属性--%>
     8   <%
     9     request.setAttribute("name","James");//设置属性name,其值为James
    10   %>
    11   <a href="requestdemo2.jsp">跳转到requestdemo2.jsp /a>
    12 </body>
    13 </html>
    View Code

     

    requestdamo2.jsp

     1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>request范围</title>
     5 </head>
     6 <body>
     7   <%--取得request 范围属性--%>
     8   <%
     9     String strName=(String)request.getAttribute("name");//取值属性name的值
    10     out.println=("request范围:name属性值为"+strName);//输出name属性值
    11   %>
    12 </body>
    13 </html>
    View Code

     

    requestdamo3.jsp(服务器跳转)

     1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>request范围</title>
     5 </head>
     6 <body>
     7   <%--在request范围设置属性--%>
     8   <%
     9     request.setAttribute("name","James");//设置属性name,其值为james
    10   %>
    11   <jsp:forward page="requestdemo2.jsp"></jsp:forward>
    12 </body>
    13 </html>
    View Code

     

  • 相关阅读:
    pytest知识梳理
    linux服务器时间不同步解决
    python re 多行匹配模式
    nginx--知识梳理
    tomcat--知识梳理
    利用springboot 重定向到静态资源功能,下载一些文件文件
    调试C++代码内存释放,在VS2019控制台显示内存泄露
    C++Primer第五版 第九章 习题9.22
    nginx 配置中间证书
    云苍穹消息推送代码
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/7586760.html
Copyright © 2011-2022 走看看