JSP response object

a response object
The response object contains information about the response to the client's request, but it is rarely used directly in JSP. It is an instance of the HttpServletResponse class. The response object has page scope, that is, when a page is accessed, the response object in the page is only valid for this visit, and the response objects of other pages are invalid for the current page.
 
Two commonly used methods of response objects


 
 
Three actual combat
<%@ page language = "java" import = "java.util.*,java.io.*" contentType = "text/html; charset=utf-8" %>
<%
    response.setContentType( "text/html;charset=utf-8" ); //Set the MIMI type of the response
   
    out.println( "<h1>response built-in object</h1>" );
    out.println( "<hr>" );
    //out.flush(); //Solve the problem that the browser output of the PrintWrite object always precedes the output of the out object
   
    PrintWriter outer = response.getWriter(); //Get the output stream object
    outer.println( "Hello everyone, I am the output stream outer object generated by the response object" );
    //response.sendRedirect("reg.jsp");//Request redirection
    // request redirection
    //response.sendRedirect("request.jsp");
    // request forwarding
    //request.getRequestDispatcher("request.jsp").forward(request, response);
%>
 
Four running results


 
 
Five little knowledge summary

 

The browser output of the PrintWrite object always precedes the output of the out object.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326757225&siteId=291194637