201819102039宝婉露

jsp九种内置对象:request, reponse, out, session, application, config, pagecontext, page, exception.
1.request对象

代表了客户端的请求信息,是接受信息传送到电脑服务器的数据。主要用于接受通过HTML协议转送到服务器的数据(包括头信息、系统信息、请求方式以及请求参数等)。request对象的作用域为一次请求。

<form action="request.jsp">
 username:<input  type="text" name="user"/><br/>
 password:<input  type="password" name="pwd"/><br/>

 <input type="submit" name="请求"/>
</form>

在这里插入图片描述
2.reponse对象
response 代表的是对客户端的请求做出动态的响应,主要是负责将电脑处理过的对象在传回到客户端。它只在jsp页面有效。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <left>
    跳转页面到腾讯首页
  </left>
  </body>
</html>

在这里插入图片描述
3.out对象
out 对象用于在Web浏览器内输出信息,并且管理应用服务器上的输出缓冲区(清理缓存).在使用out对象输出数据时,可以对数据缓冲区进行操作,及时清除缓冲区的残余数据,为其他的输出让出缓冲空间。待数据输出完毕后,要及时关闭输出流.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <pre>
<%
  out.println("<b>使用println()方法向客户端浏览器输出文字:</b>");
  out.println("Hello!");
%>
</pre>
  </body>
</html>

在这里插入图片描述
4.session对象
session对象指的是客户端与服务器的一次会话,session可以在应用程序的web页面间进行跳转时,保存用户状态直到关闭浏览器,客户端长时间不发出请求,session对象会自动消失。

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
  <base href="<%=basePath%>">
  <title>session1</title>
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<form id="form1" name="form1" method="post" action="session2.jsp">
  <div align="center">
    <table width="40%" border="0">
      <tr>
        <td width="36%"><div align="center">您的名字是:</div></td>
        <td width="64%">
          <label>
            <div align="center">
              <input type="text" name="name" />
            </div>
          </label>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <label>
            <div align="center">
              <input type="submit" name="Submit" value="提交" />
            </div>
          </label>
        </td>
      </tr>
    </table>
  </div>
</form>
</body>
</html>

在这里插入图片描述
5.application对象
application对象可将所有应用中的共有数据保存在服务器中,在服务器启动时自动创建,在服务器停止时销毁。若不销毁,则application对象中保存的信息会在整个应用中都有效。与session对象相比,application对象生命周期更长,类似于系统的“全局变量”。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
</head>
<body>
<%
  Object obj=application.getAttribute("counter");
  if (obj==null){
    application.setAttribute("counter",new Integer(1));
    out.println("该页面被访问了1次<br/>");
  }else {
    int countValue=new Integer(obj.toString());
    countValue++;
    out.println("该页面被访问了"+countValue+"次<br/>");
    application.setAttribute("counter",countValue);//java会自动装箱
  }
%>
</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值