码迷,mamicode.com
首页 > Web开发 > 详细

JSP内置对象

时间:2016-12-23 22:01:16      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:应用信息   nbsp   san   保存   ati   hang   就会   exce   str   

九大内置对象

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");

 

 

JSP内置对象

标签:应用信息   nbsp   san   保存   ati   hang   就会   exce   str   

原文地址:http://www.cnblogs.com/future-zmy/p/6216045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!