簡體   English   中英

將文件路徑字符串從jsp傳遞到Java servlet

[英]Passing file path string from jsp to java servlet

我正在將文件路徑從jsp頁面傳遞到Java servlet。 但是,一旦servlet接收到路徑, \\丟失。

JSP形式:

<form action="DownloadFiles" method="POST">
    <button class="btn btn-link" type="submit" value="C:\Users\Bob\Desktop\file.txt" name="filePath">
        <span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span>
    </button>
</form>

Java Servlet代碼:

String filePath = request.getParameter("filePath");
System.err.println(filePath);

filePath打印為

C:UsersBobDesktop\file.txt

應該:

C:\Users\Bob\Desktop\file.txt

這僅在Windows而非Linux上發生。

如何在Windows中獲得正確的文件路徑?

使用/代替\\ 這適用於Linux和Windows。

或者,使用\\\\可以。

\\\\-插入一個反斜杠字符(\\)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM