Javascript 从url加载带有中文文件名的pdf

Javascript 从url加载带有中文文件名的pdf,javascript,url,httprequest,tomcat6,Javascript,Url,Httprequest,Tomcat6,我有一个本地pdf,我试着按照文件路径将此pdf加载到iframe中 该文件有一个名称明星.pdf,路径如下所示: 当我尝试打开pdf文件时,浏览器执行此请求并失败(404): 只有包含中文字符的PDF才会出现此问题 有什么建议吗 PS:我正在使用javascript 编辑: 例如: //there's a http:// in front, I can't put more links in post var url = 'localhost:8080/path-here/teste.pd

我有一个本地pdf,我试着按照文件路径将此pdf加载到iframe中

该文件有一个名称明星.pdf,路径如下所示:

当我尝试打开pdf文件时,浏览器执行此请求并失败(404):

只有包含中文字符的PDF才会出现此问题

有什么建议吗

PS:我正在使用javascript

编辑:

例如:

//there's a http:// in front, I can't put more links in post
var url = 'localhost:8080/path-here/teste.pdf' 
var url2 = 'localhost:8080/path-here/明星.pdf'

window.open(url,"_blank") //works fine
window.open(url2,"_blank") //fails

Javascript可以处理大多数非英语字符,但您可能需要对它们进行编码,以便web浏览器识别它们。尝试将网页(服务器?)的字符集指定为UTF-8

    <head>
    <meta charset="UTF-8">
    </head>

您可能还需要为webbrowser准备字符串,我建议使用encodeURIcomponent()或encodeURI()。下面是对函数的解释
. 希望有帮助

您可以这样做,使用

<a href="yourfilepath" download="your_chinesefilename.pdf",

pdfdownloadceshi
函数下载{
var pdfFilePath=“”+”WebRoot\\download\\\“+”bank\u wage“+”.xls”;
var titleDate=新日期().格式(“yyyy-MM-dd-hh-MM-ss”);
document.getElementById(“dlink”).href=pdfFilePath;
document.getElementById(“dlink”).download=”银行流水表"+标题日期+“.xls”;
document.getElementById(“dlink”)。单击();
}

你可以看看,如何使用下载

我在你的问题标签中看到了
javascript
。你能展示一些代码吗?RFC 1738说不要在URL中使用非ascii字符,这就是你遇到这个问题的部分原因(不常见的用例)。您使用的服务器/设置是什么?请确保将您的URIEncoding设置为UTF-8,因为RFC3987也引入了IRIs,如果您想要更持久的修复,它允许未编码的UTF-8。但不确定它们是否在javascript中可用,您必须进行一些研究。这是一个tomcat服务器,uri Encoding设置为UTF-8。
<a id="dlink"  style="display:none;"></a>
<button onclick="downloadWagePdf()">
    pdfdownloadceshi 
</button>
<script type="text/javascript"> 

    function downloadWagePdf() {
        var pdfFilePath = "<%=basePath%>" + "WebRoot\\download\\" + "bank_wage" + ".xls";
        var titleDate= new Date().Format("yyyy-MM-dd hh-mm-ss");
        document.getElementById("dlink").href = pdfFilePath;
        document.getElementById("dlink").download = "银行流水表"+titleDate+".xls";
        document.getElementById("dlink").click();
    }

</script>