⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servletresponse.html

📁 java API学习JAVA的人必备之品
💻 HTML
📖 第 1 页 / 共 3 页
字号:
          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>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletResponse.html#setContentLength(int)">setContentLength</A></B>(int&nbsp;len)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletResponse.html#setContentType(java.lang.String)">setContentType</A></B>(java.lang.String&nbsp;type)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletResponse.html#setLocale(java.util.Locale)">setLocale</A></B>(java.util.Locale&nbsp;loc)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the locale of the response, if the response has not been
 committed yet.</TD>
</TR>
</TABLE>
&nbsp;
<P>

<!-- ============ FIELD DETAIL =========== -->


<!-- ========= CONSTRUCTOR DETAIL ======== -->


<!-- ============ METHOD DETAIL ========== -->

<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<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.
<P>
<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.
<P>
<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></DT>
  <DD>2.4</DD>
</DL>
</DD>
</DL>
<HR>

<A NAME="getOutputStream()"><!-- --></A><H3>
getOutputStream</H3>
<PRE>
public <A HREF="../../javax/servlet/ServletOutputStream.html" title="class in javax.servlet">ServletOutputStream</A> <B>getOutputStream</B>()
                                    throws java.io.IOException</PRE>
<DL>
<DD>Returns a <A HREF="../../javax/servlet/ServletOutputStream.html" title="class in javax.servlet"><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.
<P>
<DD><DL>

<DT><B>Returns:</B><DD>a <A HREF="../../javax/servlet/ServletOutputStream.html" title="class in javax.servlet"><CODE>ServletOutputStream</CODE></A> for writing binary data
<DT><B>Throws:</B>
<DD><CODE>java.lang.IllegalStateException</CODE> - if the <code>getWriter</code> method
 					has been called on this response
<DD><CODE>java.io.IOException</CODE> - 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.
<P>
<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><CODE>UnsupportedEncodingException</CODE> - if the character encoding returned
			by <code>getCharacterEncoding</code> cannot be used
<DD><CODE>java.lang.IllegalStateException</CODE> - if the <code>getOutputStream</code>
 			method has already been called for this 
			response object
<DD><CODE>java.io.IOException</CODE> - 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&nbsp;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 can be called repeatedly to change the character
 encoding.
 This method has no effect if it is called after
 <code>getWriter</code> has been
 called or after the response has been committed.
 <p>Containers must communicate the character encoding used for
 the servlet response's writer to the client if the protocol
 provides a way for doing so. In the case of HTTP, the character
 encoding is communicated as part of the <code>Content-Type</code>
 header for text media types. Note that the character encoding
 cannot be communicated via HTTP headers if the servlet does not
 specify a content type; however, it is still used to encode text
 written via the servlet response's writer.
<P>
<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></DT>
  <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&nbsp;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.
<P>
<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&nbsp;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 may be called repeatedly to change content type and
 character encoding.
 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.
 <p>Containers must communicate the content type and the character
 encoding used for the servlet response's writer to the client if
 the protocol provides a way for doing so. In the case of HTTP,
 the <code>Content-Type</code> header is used.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>type</CODE> - a <code>String</code> specifying the MIME 
			type of the content<DT><B>See Also:</B><DD><A HREF="../../javax/servlet/ServletResponse.html#setLocale(java.util.Locale)"><CODE>setLocale(java.util.Locale)</CODE></A>, 
<A HREF="../../javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String)"><CODE>setCharacterEncoding(java.lang.String)</CODE></A>, 
<A HREF="../../javax/servlet/ServletResponse.html#getOutputStream()"><CODE>getOutputStream()</CODE></A>, 
<A HREF="../../javax/servlet/ServletResponse.html#getWriter()"><CODE>getWriter()</CODE></A></DL>
</DD>
</DL>
<HR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -