JSP网站建设中常见的中文乱码问题-上传下载篇

      做过上传下载的朋友肯定经常遇到中文乱码的问题,没办法,谁叫这些框架呀,语言呀都不是用中文写的。

      言归正传,遇到上传下载的问题,其实我有两点要强调:

      配置xml:过滤乱码(使用spring)

   

	 <!-- 过滤乱码 -->
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>


      首先是上传,写上传的时候,在form中,一定要记得声明方法:method=“post”    -------http://blog.csdn.net/langrenbule/article/details/6932521

      在下载的时候出现中文乱码的时候

 public String getDownloadFileName() {
		setFileName(song.getSongName());
		downFileName = fileName;
		try {
			downFileName = new String(downFileName.getBytes(), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			return downFileName;
		}

,我们要进行格式转化。

特别要注意的是struts配置:

<action name = "download" class="com.music.song.action.SongAction" method = "DownLoad">
			<result name = "success" type = "stream">
			<param name = "contentType">audio/mpeg3;charset=UTF-8</param>
			<param name = "inputName">targetFile</param>
			<param name = "contentDisposition">filename=${downFileName}.mp3</param>
			</result>
</action>




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值