zoukankan      html  css  js  c++  java
  • JSP内置对象

    九大内置对象

    jsp

    servlet

     

    对象名

    类型

    使用范围

    request

    HttpServletRequest

    请求 浏览器--->服务器

    response

    HttpServletResponse

    返回 服务器--->浏览器

    config

    ServletConfig

    用来获取web.xml中的信息

    application

    ServletContext

    整个项目中的全局信息

    exception

    Thrawable

    捕获异常 try/catch  throws

    page

    this

    当前对象,当前页面对象

    out

    JspWriter---->PrintWriter

    当前页面输出流

    pageContext

    PageContext

    当前页面的上下文,整个页面

    Session

    HttpSession

    会话  浏览器和服务器通讯

    1  out  对象  JspWriter 带缓冲的PrinterWriter  就是输出流   

      使用范围是当前页面,超出了当前页无效

    PrinterWriter    直接向浏览器输出内容

    JspWriter       Jsp 缓冲区写内容

    out.print()

    out.println();

     

     

    2  pageContext 对象 当前页面的上下文     

       使用范围是当前页面,超出了当前页无效

    存值 pageContext.setAttribute("username","zhangsan");

    取值pageContext.getAttribute("username")

     

     

    3  page==this 对象 一般用在编译指令中 <%@ page   %>

     

    4  request 请求  浏览器到服务器

     

    当前请求存属性值

    request.setAttribute("name","godyang");

    当前请求取值

    request.getAttribute("name")

    请求传递参数

    <a href="b.jsp?name=shunshun">  b.jsp</a>

    或者

      <form  action="b.jsp"  method=post  >

       <input  type=text name="name" value="shunshun" />

       </form>

     

    取得请求参数的值

    request.getParameter(参数名);  request.getParameterValues(参数名)

    5 reponse  返回  服务器返回到浏览器

     

    获取返回流

    PrintWriter out = response.getWriter();

    返回内容形式

    response.setContentType("text/html");

    返回的编码

    response.setCharacterEncoding("UTF-8");

    页面重定向

    response.sendRedirect("index.jsp");

    浏览器端保存cookie对象

    response.addCookie()

     

     

     

     

    6 session 会话  浏览器和服务器通讯    当浏览器关闭的时候会话结束

    当浏览器第一访问服务器的时候就会产生一个会话

    保存会话信息

     session.setAttribute("uname","abc");

    获取会话信息

     session.getAttribute("uname");

     

     

    7 application 应用   tomcat启动的时候整个项目就是一个应用

       当把值存入应用中,只有当tomcat关闭的时候才销毁

     

    保存应用信息

    application.setAttribute("app","appInfo");

    获取应用信息

     application.getAttribute("app");

     

     

  • 相关阅读:
    HDU.2899.Strange fuction(牛顿迭代)
    BZOJ.3771.Triple(母函数 FFT 容斥)
    树的实现(2)
    树的练习
    死锁问题
    进程的三种状态
    线程的同步与实现
    进程间通信详解
    进程和线程以及它们的区别
    https协议
  • 原文地址:https://www.cnblogs.com/future-zmy/p/6216045.html
Copyright © 2011-2022 走看看