解决客户端重定向,URL地址中文乱码的问题。nameString = URLEncoder.encode(nameString, "utf-8");

当表单数据提交到后台Servlet AddUser后,若username包含中文,会导致重定向URL出现乱码。为解决此问题,需要在生成重定向URL前,使用URLEncoder.encode(nameString, "utf-8")对username进行编码处理,确保URL中中文字符正常显示。" 110613772,10294683,32位系统下Java开发环境搭建指南,"['Java开发环境', 'JDK安装', '环境变量', 'Eclipse', '32位软件']
摘要由CSDN通过智能技术生成

先通过表单向后台递交数据

<!DOCTYPE html>
<html>
  <head>
    <title>MyHtml.html</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
   <form action="AddUser" method="post">
    姓名:<input type="text" name="username"><br>
 密码:<input type="password" name="pass"><br/>
    <input type="submit" value="提交">
    </form>
     </body>
</html>

数据递交到AddUser这个servlet之

package sy; import java.io.BufferedReader; import java.net.*; import org.json.*; import java.io.*; public class POIService { private static String urlString="https://restapi.amap.com/v3/place/text?"; private String REQUEST_URL; public String getREQUEST_URL() { return REQUEST_URL; } public void setREQUEST_URL(String REQUEST_URL) { //��һ���иĶ� this.REQUEST_URL=REQUEST_URL; } public POIService (String params) { this.REQUEST_URL=urlString+params; } public String getPOIinfo() { StringBuffer resultBuffer=new StringBuffer(); try { URL url=new URL(this.REQUEST_URL); URLConnection connection=url.openConnection(); BufferedReader bReader=new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8")); String strlineString=null; while ((strlineString=bReader.readLine())!=null) { resultBuffer.append(strlineString); } bReader.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } //System.out.print(resultBuffer.toString()); return resultBuffer.toString(); } public int parseJson(String resultString,int currentPage,int offset) throws Exception{ JSONObject jsonResult=new JSONObject(resultString); int status=jsonResult.getInt("status"); if (status==0) { System.out.print("ʧ��"); return -1; } else { JSONArray poiArr=jsonResult.getJSONArray("pois"); int totalcount = jsonResult.getInt("count"); System.out.print("����"+totalcount+"���"); for (int i = 0; i < poiArr.length(); i++) { JSONObject poiObj=poiArr.getJSONObject(i); String idString=poiObj.getString("idString"); String nameString=poiObj.getString("nameString"); String typeString=poiObj.getString("typeString"); String addressString=poiObj.getString("addressString"); String locationString=poiObj.getString("locationString"); String citynameString=poiObj.getString("citynameString"); String adnameString=poiObj.getString("adnameString"); POI poi=new POI(idString,nameString,typeString,addressString,locationString,citynameString,adnameString); System.out.println(((currentPage-1)*offset+i+1)+"|"+poi.getIdString()+"|"+poi.getNameString()+"|"+poi.getTypeString()+"|"+poi.getAddressString()+"|"+poi.getLocationString()+"|"+poi.getCitynameString()+"|"+poi.getAdnameString()); } System.out.println("------------"); return poiArr.length(); }请帮我检查这份代码的问题
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值