<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
比如说 用户名为 “ 好好学习 ”
在传递之前使用 URLEncoder.encoder() 编码后再传递
String username = URLEncoder.encode (“ 好好学习 ”) ;
接收显示时
String username = URLDecoder.decoder( new String( request.getParameter("username").getBytes("iso8859-1") , "utf-8" ) , "utf-8" )
分开就是:
1
通过使用指定的
charset
(
tomcat
默认的是
iso8859-1
)解码指定的
byte
数组,构造一个新的
String
String strBytes = request.getParameter( "username" ).getBytes( "iso8859-1" ) ;
2
通过使用指定的
charset
解码指定的
byte
数组,构造一个新的
String
String utfStr = new String(strBytes, "utf-8" ) ;
3 使用指定的编码机制对字符串解码
Strign username = URLDecoder.decode (utfStr, "utf-8" ) ;
本文介绍如何使用URLEncoder.encode()进行URL编码,并演示了如何在Java中对接收的数据进行正确的解码过程。文章详细解释了从编码到解码的具体步骤,帮助理解跨字符集的数据处理。
4万+

被折叠的 条评论
为什么被折叠?



