您好,我正在尝试获取一个请求参数,该参数是一个文件的 URL 路径:
我正在使用 XSL 文件中的模板来“粘贴”带有 onclick 事件的 div:
<div onclick="openPDF(700,500,'getDoc?pathpdf={./.}&type=pdf&nocache='+Math.random(),'scrollbars=yes,toolbar=no,status=yes,resizable=yes,menubar=no,location=no');" align="center">
<img src='Images/pdfIconsmall.png' width='12' style='height:12' />
</div>
这部分 -> pathpdf={./.} 将收到这样的 url:
路径pdf=\\SERVER02\work\area51\docs\ws\00120130000261_101912.pdf
参数已按预期发送,但在服务器端,当我尝试执行 System.out 该参数的我收到了这个值:
->->->路径:SERVER02workarea51docsws 00120130000261_101912.pdf
转义是由 servlet 进行的还是我的应用程序中的某些东西在进行转义?
谢谢
编辑
我用与下面的 answear 不同但相似的方式制作了这个:string-replace-all
<xsl:when test="string-length(./.) >0">
<xsl:variable name="pathpdf">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="./." />
<xsl:with-param name="replace" select="'\'" />
<xsl:with-param name="by" select="'\\'" />
</xsl:call-template>
</xsl:variable>
<div onclick="openPDF(700,500,'getDoc?pathpdf={$pathpdf}&type=pdf&nocache='+Math.random(),'scrollbars=yes,toolbar=no,status=yes,resizable=yes,menubar=no,location=no');" align="center">
<img src='Images/pdfIconsmall.png' width='12' style='height:12' />
</div>
</xsl:when>
最佳答案
在将请求发送到服务器之前,您必须对 URL 参数值进行编码。
这个
pathpdf=\SERVER02\work\area51\docs\ws\00120130000261_101912.pdf
需要变成这样:
pathpdf=%5CSERVER02%5Cwork%5Carea51%5Cdocs%5Cws%5C00120130000261_101912.pdf
如果您从 java 应用程序提交请求,请将所有参数编码为
URLEncoder.encode(parameterValue);
使用 XSLT,尝试:
url:encode('your_url_goes_here');
关于Java 1.3 Servlet getParameter 用于作为 URL 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17302759/