1. out对象
javax.servlet.jsp.JspWriter类的对象,通过PrintWriter out = response.getWriter() 来获取out对象。
2. request对象
javax.servlet.ServletRequest 类的对象,通过GET/POST参数可获取。
3 response对象
javax.servlet.ServletResponse类的对象,通过GET/POST参数可获取。
4 session对象
javax.servlet.http.HttpSession 类的对象,通过request.getSession() 方法可以获得session对象。
5 application对象
javax.servlet.ServletContext类的对象,通过 this.getServletContext() 可以获得,this是servlet继承的javax.servlet.http.HttpServlet类的父类javax.servlet.GenericServlet类中的方法。
6. pageContext对象
javax.servlet.jsp.PageContext类的对象,通过:
JspFactory fac = JspFactory.getDefaultFactory();
PageContext pageContext = fac.getPageContext(this, request,response, null, false, JspWriter.DEFAULT_BUFFER, true) 方式获取pageContext对象。
注: pageContext对象中封装了jsp中的其他的内置对象,可以通过此对象过去其他的jsp中的对象。
源码:
HttpSession session = request.getSession(); //获取session对象
ServletConfig config= this.getServletConfig(); //获取config对象
JspFactory fac = JspFactory.getDefaultFactory(); //获取pageContext对象
PageContext pageContext = fac.getPageContext(this, request,response,
null, false, JspWriter.DEFAULT_BUFFER, true);
PrintWriter out = response.getWriter(); //获取out对象
ServletContext application=this.getServletContext(); //获取application对象
本文详细介绍了JSP页面中的六个内置对象:out、request、response、session、application及pageContext。这些对象对于理解和使用JSP进行Web开发至关重要,涵盖了从输出处理到上下文管理等各个方面。
4116

被折叠的 条评论
为什么被折叠?



