JSP nine implicit objects
Request
Response
Config
Application
Exception
Session
Page
Out
PageContext
Out implicit object
The out implicit object is used to send text data to the client.
The out object is returned by calling the getOut method of the pageContext object. Its function and usage are very similar to the PrintWriter object returned by the ServletResponse. getWriter method.
The out implicit object type on the JSP page is JspWriter. JspWriter is equivalent to a PrintWriter with the cache function. You can adjust the cache size by setting the buffer attribute of the page instruction on the JSP page, even disable its cache.
The out object calls ServletResponse only when the content written to the out object meets any of the following conditions. the getWriter method returns the PrintWriter object to write the content in the buffer zone of the out object to the buffer zone provided by the Servlet engine:
The buffer attribute of the page instruction is set to disable the cache function of the out object.
The buffer of the out object is full.
End of the entire JSP page
PageContext object
The pageContext object is the most important object in JSP technology. It represents the running environment of JSP pages. This object not only encapsulates references to other 8 hidden objects, but also is a domain object, it can be used to save data. In addition, this object also encapsulates some common operations that are often involved in web development, such as introducing and redirecting other resources and retrieving attributes in other domain objects.
Here is an example: use JSP to download files.
<% @ Page import = "java.net. URLEncoder "%> <% @ page import =" java. io. file "%> <% @ page import =" java. io. inputStream "%> <% @ page import =" java. io. fileInputStream "%> <% @ page import =" java. io. outputStream "%> <% @ page language =" java "import =" java. util. * "pageEncoding =" ISO-8859-1 "%> <%
String path = getServletContext (). getRealPath ("./images/11.jpg ");
File file = new File (path );
InputStream is = new FileInputStream (file );
Response. setHeader ("content-disposition", "attachment; filename =" + URLEncoder. encode (file. getName (), "UTF-8 "));
OutputStream OS = response. getOutputStream ();
Byte B [] = new byte [1024];
Int flag = 0;
While (flag = is. read (B ))! =-1 ){
OS. write (B, 0, flag );
}
OS. close ();
Is. close ();
%>
Remember that there must be no space.
Chenglong0513