📄 servletresponse.html
字号:
Sets the preferred buffer size for the body of the response.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String)">setCharacterEncoding</A></B>(java.lang.String charset)</CODE><BR> Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/ServletResponse.html#setContentLength(int)">setContentLength</A></B>(int len)</CODE><BR> Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/ServletResponse.html#setContentType(java.lang.String)">setContentType</A></B>(java.lang.String type)</CODE><BR> Sets the content type of the response being sent to the client, if the response has not been committed yet.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../javax/servlet/ServletResponse.html#setLocale(java.util.Locale)">setLocale</A></B>(java.util.Locale loc)</CODE><BR> Sets the locale of the response, setting the <code>Content-Language</code> header, if the response has not been committed yet.</TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="getCharacterEncoding()"><!-- --></A><H3>getCharacterEncoding</H3><PRE>public java.lang.String <B>getCharacterEncoding</B>()</PRE><DL><DD>Returns the name of the character encoding (MIME charset) used for the body sent in this response. The character encoding may have been specified explicitly using the <A HREF="../../javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String)"><CODE>setCharacterEncoding(java.lang.String)</CODE></A> or <A HREF="../../javax/servlet/ServletResponse.html#setContentType(java.lang.String)"><CODE>setContentType(java.lang.String)</CODE></A> methods, or implicitly using the <A HREF="../../javax/servlet/ServletResponse.html#setLocale(java.util.Locale)"><CODE>setLocale(java.util.Locale)</CODE></A> method. Explicit specifications take precedence over implicit specifications. Calls made to these methods after <code>getWriter</code> has been called or after the response has been committed have no effect on the character encoding. If no character encoding has been specified, <code>ISO-8859-1</code> is returned. <p>See RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) for more information about character encoding and MIME.<DD><DL><DT><B>Returns:</B><DD>a <code>String</code> specifying the name of the character encoding, for example, <code>UTF-8</code></DL></DD></DL><HR><A NAME="getContentType()"><!-- --></A><H3>getContentType</H3><PRE>public java.lang.String <B>getContentType</B>()</PRE><DL><DD>Returns the content type used for the MIME body sent in this response. The content type proper must have been specified using <A HREF="../../javax/servlet/ServletResponse.html#setContentType(java.lang.String)"><CODE>setContentType(java.lang.String)</CODE></A> before the response is committed. If no content type has been specified, this method returns null. If a content type has been specified and a character encoding has been explicitly or implicitly specified as described in <A HREF="../../javax/servlet/ServletResponse.html#getCharacterEncoding()"><CODE>getCharacterEncoding()</CODE></A>, the charset parameter is included in the string returned. If no character encoding has been specified, the charset parameter is omitted.<DD><DL><DT><B>Returns:</B><DD>a <code>String</code> specifying the content type, for example, <code>text/html; charset=UTF-8</code>, or null<DT><B>Since: </B><DD>2.4</DD></DL></DD></DL><HR><A NAME="getOutputStream()"><!-- --></A><H3>getOutputStream</H3><PRE>public <A HREF="../../javax/servlet/ServletOutputStream.html">ServletOutputStream</A> <B>getOutputStream</B>() throws java.io.IOException</PRE><DL><DD>Returns a <A HREF="../../javax/servlet/ServletOutputStream.html"><CODE>ServletOutputStream</CODE></A> suitable for writing binary data in the response. The servlet container does not encode the binary data. <p> Calling flush() on the ServletOutputStream commits the response. Either this method or <A HREF="../../javax/servlet/ServletResponse.html#getWriter()"><CODE>getWriter()</CODE></A> may be called to write the body, not both.<DD><DL><DT><B>Returns:</B><DD>a <A HREF="../../javax/servlet/ServletOutputStream.html"><CODE>ServletOutputStream</CODE></A> for writing binary data<DT><B>Throws:</B><DD>IllegalStateException - if the <code>getWriter</code> method has been called on this response<DD>java.io.IOException - if an input or output exception occurred<DT><B>See Also: </B><DD><A HREF="../../javax/servlet/ServletResponse.html#getWriter()"><CODE>getWriter()</CODE></A></DL></DD></DL><HR><A NAME="getWriter()"><!-- --></A><H3>getWriter</H3><PRE>public java.io.PrintWriter <B>getWriter</B>() throws java.io.IOException</PRE><DL><DD>Returns a <code>PrintWriter</code> object that can send character text to the client. The <code>PrintWriter</code> uses the character encoding returned by <A HREF="../../javax/servlet/ServletResponse.html#getCharacterEncoding()"><CODE>getCharacterEncoding()</CODE></A>. If the response's character encoding has not been specified as described in <code>getCharacterEncoding</code> (i.e., the method just returns the default value <code>ISO-8859-1</code>), <code>getWriter</code> updates it to <code>ISO-8859-1</code>. <p>Calling flush() on the <code>PrintWriter</code> commits the response. <p>Either this method or <A HREF="../../javax/servlet/ServletResponse.html#getOutputStream()"><CODE>getOutputStream()</CODE></A> may be called to write the body, not both.<DD><DL><DT><B>Returns:</B><DD>a <code>PrintWriter</code> object that can return character data to the client<DT><B>Throws:</B><DD>java.io.UnsupportedEncodingException - if the character encoding returned by <code>getCharacterEncoding</code> cannot be used<DD>IllegalStateException - if the <code>getOutputStream</code> method has already been called for this response object<DD>java.io.IOException - if an input or output exception occurred<DT><B>See Also: </B><DD><A HREF="../../javax/servlet/ServletResponse.html#getOutputStream()"><CODE>getOutputStream()</CODE></A>, <A HREF="../../javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String)"><CODE>setCharacterEncoding(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="setCharacterEncoding(java.lang.String)"><!-- --></A><H3>setCharacterEncoding</H3><PRE>public void <B>setCharacterEncoding</B>(java.lang.String charset)</PRE><DL><DD>Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the character encoding has already been set by <A HREF="../../javax/servlet/ServletResponse.html#setContentType(java.lang.String)"><CODE>setContentType(java.lang.String)</CODE></A> or <A HREF="../../javax/servlet/ServletResponse.html#setLocale(java.util.Locale)"><CODE>setLocale(java.util.Locale)</CODE></A>, this method overrides it. Calling <A HREF="../../javax/servlet/ServletResponse.html#setContentType(java.lang.String)"><CODE>setContentType(java.lang.String)</CODE></A> with the <code>String</code> of <code>text/html</code> and calling this method with the <code>String</code> of <code>UTF-8</code> is equivalent with calling <code>setContentType</code> with the <code>String</code> of <code>text/html; charset=UTF-8</code>. <p>This method has no effect if it is called after <code>getWriter</code> has been called or after the response has been committed.<DD><DL><DT><B>Parameters:</B><DD><CODE>charset</CODE> - a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)<DT><B>Since: </B><DD>2.4</DD><DT><B>See Also: </B><DD><A HREF="../../javax/servlet/ServletResponse.html#setContentType(java.lang.String)"><CODE>#setLocale</CODE></A></DL></DD></DL><HR><A NAME="setContentLength(int)"><!-- --></A><H3>setContentLength</H3><PRE>public void <B>setContentLength</B>(int len)</PRE><DL><DD>Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.<DD><DL><DT><B>Parameters:</B><DD><CODE>len</CODE> - an integer specifying the length of the content being returned to the client; sets the Content-Length header</DL></DD></DL><HR><A NAME="setContentType(java.lang.String)"><!-- --></A><H3>setContentType</H3><PRE>public void <B>setContentType</B>(java.lang.String type)</PRE><DL><DD>Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, <code>text/html;charset=UTF-8</code>. The response's character encoding is only set from the given content type if this method is called before <code>getWriter</code> is called. <p>This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after <code>getWriter</code> has been called or after the response has been committed.<DD><DL>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -