加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

用ajax下载smartupload的内容,无法显示汉字

发布时间:2020-12-15 21:02:12 所属栏目:百科 来源:网络整理
导读:服务器端:public void doGet(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{req.setCharacterEncoding("GBK");// 新建一个SmartUpload对象SmartUpload su = new SmartUpload();su.initialize(this.getServletConfig
服务器端:
public void doGet(HttpServletRequest req,HttpServletResponse resp)
			throws ServletException,IOException{
		req.setCharacterEncoding("GBK");
		// 新建一个SmartUpload对象
		SmartUpload su = new SmartUpload();
		su.initialize(this.getServletConfig(),req,resp);
		// 设定contentDisposition为null以禁止浏览器自动打开文件,   
		//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为   
		//doc时,浏览器将自动用word打开它。扩展名为pdf时,   
		//浏览器将用acrobat打开。 
		
		su.setContentDisposition(null);
		//下载文件
		try {
			su.downloadFile("D://upload/"+"test.txt");
		} catch (SmartUploadException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

客户端:
<script>
 function getFile(){
        	$.get("<%=basePath%>LoadFileServlet","",function(data){
        		alert(data);
        	});
        }
</script>
<a href="#" onclick="getFile()">getfile</a>

txt中的中文内容不显示,如果通过超链接访问server端,下载后没有乱码

先MARK下,以后再看看

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读