Servlet - response related objects

 

the data objects are used to response to the browser in response to an object

 

// set the response header
 // the setHeader (): adding header information response, if the key is present, this would override the value
 // the addHeader (): add information in the response header, if the key is present, not covered 
resp.setHeader ( " setKey " , " setValue " );
resp.addHeader("addKey", "addValue");

// Setup Response status code
 // resp.sendError (404, "ERR info");

// set the response encoding format
 // first embodiment: 
 // resp.setHeader ( "Content-type", "text / HTML; charset = UTF-. 8");
 // second way: 
resp.setContentType ( " text / HTML; charset = UTF-. 8 " );

// set response entity, in response to specific data to the browser 
. Resp.getWriter () Write ( " <h1 of> Hello </ h1 of> " );

Guess you like

Origin www.cnblogs.com/mpci/p/12099738.html