Reputation: 767
I am passing a file path from a jsp page to a Java servlet. But once the path is received by the servlet the \
are missing.
JSP form:
<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 Code:
String filePath = request.getParameter("filePath");
System.err.println(filePath);
filePath
is printed out as
C:UsersBobDesktop\file.txt
Should be:
C:\Users\Bob\Desktop\file.txt
This is only happening on Windows not linux.
How can I get the correct file path in Windows?
Upvotes: 0
Views: 964
Reputation: 2737
Use /
instead of \
. This works for both Linux and Windows.
Or, using \\
will do.
\\ - Insert a backslash character(\).
Upvotes: 1