<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--NewPage--> <HTML> <HEAD> <!-- Generated by javadoc (build 1.4.2-rc) on Fri Jun 13 00:14:25 PDT 2003 --> <TITLE> URLEncoder (Java 2 Platform SE v1.4.2) </TITLE> <META NAME="keywords" CONTENT="java.net.URLEncoder class"> <META NAME="keywords" CONTENT="encode()"> <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"> <SCRIPT type="text/javascript"> function windowTitle() { parent.document.title="URLEncoder (Java 2 Platform SE v1.4.2)"; } </SCRIPT> </HEAD> <BODY BGCOLOR="white" onload="windowTitle();"> <!-- ========= START OF TOP NAVBAR ======= --> <A NAME="navbar_top"><!-- --></A> <A HREF="#skip-navbar_top" title="Skip navigation links"></A> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> <TR> <TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A NAME="navbar_top_firstrow"><!-- --></A> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/URLEncoder.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR> </TABLE> </TD> <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> <b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.4.2</b></EM> </TD> </TR>
<TR> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/net/URLDecoder.html" title="class in java.net"><B>PREV CLASS</B></A> <A HREF="../../java/net/URLStreamHandler.html" title="class in java.net"><B>NEXT CLASS</B></A></FONT></TD> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" target="_top"><B>FRAMES</B></A> <A HREF="URLEncoder.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </SCRIPT> <NOSCRIPT> <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A> </NOSCRIPT> </FONT></TD> </TR> <TR> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> </TR> </TABLE> <A NAME="skip-navbar_top"></A> <!-- ========= END OF TOP NAVBAR ========= --> <HR> <!-- ======== START OF CLASS DATA ======== --> <H2> <FONT SIZE="-1"> java.net</FONT> <BR> Class URLEncoder</H2> <PRE> <A HREF="../../java/lang/Object.html" title="class in java.lang">java.lang.Object</A> <IMG SRC="../../resources/inherit.gif" ALT="extended by"><B>java.net.URLEncoder</B> </PRE> <HR> <DL> <DT>public class <B>URLEncoder</B><DT>extends <A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></DL> <P> Utility class for HTML form encoding. This class contains static methods for converting a String to the <CODE>application/x-www-form-urlencoded</CODE> MIME format. For more information about HTML form encoding, consult the HTML <A HREF="http://www.w3.org/TR/html4/">specification</A>. 用于HTML表单编码的工具类,这个类含有将字符串编码为application/x-www-form-urlencoded这样 MIME格式的方法。关于HTML表单编码的更多细节,查阅HTML规范。 <p> When encoding a String, the following rules apply: 当对字符串编码时,遵循以下规则: <p> <ul> <li>The alphanumeric characters "<code>a</code>" through "<code>z</code>", "<code>A</code>" through "<code>Z</code>" and "<code>0</code>" through "<code>9</code>" remain the same. 字母数字的字符,a-z,A-Z,0-9保持不变。 <li>The special characters "<code>.</code>", "<code>-</code>", "<code>*</code>", and "<code>_</code>" remain the same. 特殊字符.,-,*和_保持不变。 <li>The space character "<code> </code>" is converted into a plus sign "<code>+</code>". 空格字符被转换成+号。 <li>All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "<code>%<i>xy</i></code>", where <i>xy</i> is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used. 其他所有的字符都是不安全的,首先按照编码规范转换成一个或更多的字节。每一个字节被表示成 3字符的字符串%xy。xy是该字节的两个十六进制位表示,推荐的编码规范是UTF-8。 然而,出于兼容性考虑,如果编码没有被指定,那么默认平台所使用的编码。 </ul> <p> For example using UTF-8 as the encoding scheme the string "The string ü@foo-bar" would get converted to "The+string+%C3%BC%40foo-bar" because in UTF-8 the character ü is encoded as two bytes C3 (hex) and BC (hex), and the character @ is encoded as one byte 40 (hex). 以UTF-8编码举例,字符串“The string ü@foo-bar”将被转换成“The+string+%C3%BC%40foo-bar”, 因为在UTF-8中,字符ü被编码成C3(16进制)和BC(16进制),字符@被编码成一个字节40(16进制)。 <P> <P> <DL> <DT><B>Since:</B></DT> <DD>JDK1.0</DD> </DL> <HR> <P> <!-- ======== NESTED CLASS SUMMARY ======== --> <!-- =========== FIELD SUMMARY =========== -->
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A> <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=2><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD> </TR> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>static <A HREF="../../java/lang/String.html" title="class in java.lang">String</A></CODE></FONT></TD> <TD><CODE><B><A HREF="../../java/net/URLEncoder.html#encode(java.lang.String)">encode</A></B>(<A HREF="../../java/lang/String.html" title="class in java.lang">String</A> s)</CODE> <BR> <B>Deprecated.</B> <I>The resulting string may vary depending on the platform's default encoding. Instead, use the encode(String,String) method to specify the encoding. 结果字符串可能根据平台默认编码而改变。代之以使用encode(String,String)方法来指定编码。</I></TD> </TR> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE>static <A HREF="../../java/lang/String.html" title="class in java.lang">String</A></CODE></FONT></TD> <TD><CODE><B><A HREF="../../java/net/URLEncoder.html#encode(java.lang.String, java.lang.String)">encode</A></B>(<A HREF="../../java/lang/String.html" title="class in java.lang">String</A> s, <A HREF="../../java/lang/String.html" title="class in java.lang">String</A> enc)</CODE> <BR> Translates a string into <code>application/x-www-form-urlencoded</code> format using a specific encoding scheme. 使用指定的编码规范将字符串转换成application/x-www-form-urlencoded格式。</TD> </TR> </TABLE> <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> <TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></B></TD> </TR> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD><CODE><A HREF="../../java/lang/Object.html#clone()">clone</A>, <A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/lang/Object.html#finalize()">finalize</A>, <A HREF="../../java/lang/Object.html#getClass()">getClass</A>, <A HREF="../../java/lang/Object.html#hashCode()">hashCode</A>, <A HREF="../../java/lang/Object.html#notify()">notify</A>, <A HREF="../../java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../java/lang/Object.html#toString()">toString</A>, <A HREF="../../java/lang/Object.html#wait()">wait</A>, <A HREF="../../java/lang/Object.html#wait(long)">wait</A>, <A HREF="../../java/lang/Object.html#wait(long, int)">wait</A></CODE></TD> </TR> </TABLE> <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="encode(java.lang.String)"><!-- --></A><H3> encode</H3> <PRE> public static <A HREF="../../java/lang/String.html" title="class in java.lang">String</A> <B>encode</B>(<A HREF="../../java/lang/String.html" title="class in java.lang">String</A> s)</PRE> <DL> <DD><B>Deprecated.</B> <I>The resulting string may vary depending on the platform's default encoding. Instead, use the encode(String,String) method to specify the encoding. 结果字符串可能根据平台默认编码而改变。代之以使用encode(String,String)方法来指定编码。</I> <P> <DD>Translates a string into <code>x-www-form-urlencoded</code> format. This method uses the platform's default encoding as the encoding scheme to obtain the bytes for unsafe characters. 将字符串转换成application/x-www-form-urlencoded格式。该方法使用平台默认的编码作为编码规范来获得非安全字符的字节。 <P> <DD><DL> <DT><B>Parameters:</B><DD><CODE>s</CODE> - <code>String</code> to be translated. 要转换的字符串。 <DT><B>Returns:</B><DD>the translated <code>String</code>. 转换后的字符串。</DL> </DD> </DL> <HR> <A NAME="encode(java.lang.String, java.lang.String)"><!-- --></A><H3> encode</H3> <PRE> public static <A HREF="../../java/lang/String.html" title="class in java.lang">String</A> <B>encode</B>(<A HREF="../../java/lang/String.html" title="class in java.lang">String</A> s, <A HREF="../../java/lang/String.html" title="class in java.lang">String</A> enc) throws <A HREF="../../java/io/UnsupportedEncodingException.html" title="class in java.io">UnsupportedEncodingException</A></PRE> <DL> <DD>Translates a string into <code>application/x-www-form-urlencoded</code> format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters. 使用指定的编码规范将字符串转换成application/x-www-form-urlencoded格式。该方法使用支持的编码规范来获得非安全字符的字节。 <p> <em><strong>Note:</strong> The <a href= "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars"> World Wide Web Consortium Recommendation</a> states that UTF-8 should be used. Not doing so may introduce incompatibilites.</em> World Wide Web Consortium Recommendation声明应该使用UTF-8,不这样做可能造成不兼容。 <P> <DD><DL> <DT><B>Parameters:</B><DD><CODE>s</CODE> - <code>String</code> to be translated. 要转换的字符串。<DD><CODE>enc</CODE> - The name of a supported <a href="../lang/package-summary.html#charenc">character encoding</a>. 支持的字符编码名称。 <DT><B>Returns:</B><DD>the translated <code>String</code>. 转换后的字符串。 <DT><B>Throws:</B> <DD><CODE><A HREF="../../java/io/UnsupportedEncodingException.html" title="class in java.io">UnsupportedEncodingException</A></CODE> - If the named encoding is not supported 如果不支持指定名称的编码抛出<DT><B>Since:</B></DT> <DD>1.4</DD> <DT><B>See Also:</B><DD><A HREF="../../java/net/URLDecoder.html#decode(java.lang.String, java.lang.String)"><CODE>URLDecoder.decode(java.lang.String, java.lang.String)</CODE></A></DL> </DD> </DL> <!-- ========= END OF CLASS DATA ========= --> <HR> <!-- ======= START OF BOTTOM NAVBAR ====== --> <A NAME="navbar_bottom"><!-- --></A> <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> <TR> <TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A NAME="navbar_bottom_firstrow"><!-- --></A> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/URLEncoder.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR> </TABLE> </TD> <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> <b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.4.2</b></EM> </TD> </TR>
<TR> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/net/URLDecoder.html" title="class in java.net"><B>PREV CLASS</B></A> <A HREF="../../java/net/URLStreamHandler.html" title="class in java.net"><B>NEXT CLASS</B></A></FONT></TD> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" target="_top"><B>FRAMES</B></A> <A HREF="URLEncoder.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </SCRIPT> <NOSCRIPT> <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A> </NOSCRIPT> </FONT></TD> </TR> <TR> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> </TR> </TABLE> <A NAME="skip-navbar_bottom"></A> <!-- ======== END OF BOTTOM NAVBAR ======= --> <HR> <font size="-1"><a href="http://java.sun.com/cgi-bin/bugreport.cgi">Submit a bug or feature</a><br>For further API reference and developer documentation, see <a href="../../../relnotes/devdocs-vs-specs.html">Java 2 SDK SE Developer Documentation</a>. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. <p>Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to <a href="../../../relnotes/license.html">license terms</a>. Also see the <a href="http://java.sun.com/docs/redist.html">documentation redistribution policy</a>.</font> </BODY> </HTML>

|