url 汉字 乱码

1.url中有汉字数据需要传到后台存入database,在js中

 

encodeURIComponent(URIstring)

 

传到后台是乱码。

 

解决方法:

在tomcat 的server.xml 中

在下配置中添加红色部分即可。

 

<Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" port="8089" redirectPort="8443" URIEncoding="UTF-8"/>

 

2. 下载文件有乱码

从页面通过js拼字符串,然后通过request 把数据 push 到servlet 端,在servlet 端转化成文件流再 push 到客户端以txt 的形式。

 

	public void pushData(HttpServletResponse response, String content) throws Exception{ 
		ServletOutputStream out = null; 
		InputStream is = null; 
		try{ 
			String downloadDisplayName =DOWNLOAD_DISPLAY_NAME; 
			is = new ByteArrayInputStream(content.getBytes("UTF-8")); 
			response.setContentType("application/octet-stream");
			response.setHeader("Content-disposition","attachment; filename=" + downloadDisplayName);
			response.setCharacterEncoding("UTF-8");
			// Get the output stream of the response
			out = response.getOutputStream(); 
			int c; 
			while ((c = is.read()) != -1){ 
			out.write(c); 
			} 
			out.flush(); 
		}catch(IOException ex){ 
			logger.error(ex.getMessage(), ex); 
			ex.printStackTrace(); 
		}finally{ 
			if (is != null){ 
				is.close(); 
			} 
			if (out != null){ 
				out.flush(); 
				out.close(); 
			} 
		} 
	} 

 如果是content.getBytes())就会有乱码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值