javaweb九个内置对象

  1. page对象:
    代表页面本身,即svrelet的this,类型就是生成的Serlet。

  2. application对象:
    application 对象可将信息保存在服务器中,直到服务器关闭,否则application对象中保存的信息会在整个应用中都有效。

<html>
<head><title>201819101023 姚雪丽</title></head>
<body>
     <h2>application对象</h2>
     <%
             String serverPath = application.getContextPath();
       out.println(serverPath);
       application.setAttribute("", "");
       %>
</body>
</html>
  1. config:
    config 对象的主要作用是取得服务器的配置信息。通过 pageConext对象的 getServletConfig() 方法可以获取一个config对象。

  2. exception:
    exception 对象的作用是显示异常信息,只有在包含 isErrorPage=“true” 的页面中才可以被使用,在一般的JSP页面中使用该对象将无法编译JSP文件。

  3. out:
    out 对象用于在Web浏览器内输出信息,并且管理应用服务器上的输出缓冲区。

  4. pageContext:
    pageContext 对象的作用是取得任何范围的参数,可以获取 JSP页面的out、request、reponse、session、application 等对象。

  5. requext:
    request 对象是 javax.servlet.httpServletRequest类型的对象。

 <%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Insert title here</title>
  </head>
  <body>
     <form action="request-receiver.jsp" method="post">
         username:<input  type="text" name="user"/><br/>
         password:<input  type="password" name="pwd"/><br/>
         
         <input  type="submit" name="登陆"/>        
     
     </form>
 </body>
 </html>
  1. reponse:
    response 代表的是对客户端的响应,主要是将JSP容器处理过的对象传回到客户端。
 <%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Insert title here</title>
</head>
 <body>
     请重新登录
 </body>
 </html>
  1. session:
    session 对象是由服务器自动创建的与用户请求相关的对象。
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title>1111</title>
     </head>
 <body>
     <%
             String name = (String)session.getAttribute("name");
             String pwd = (String)session.getAttribute("pwd");
             out.println("登陆成功");
             out.println(name+","+pwd);
             System.out.println(session.getId()); //获取当前回话的id
         %>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值