develop1
develop1

Reputation: 767

Passing file path string from jsp to java servlet

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

Answers (1)

Ofisora
Ofisora

Reputation: 2737

Use / instead of \. This works for both Linux and Windows.

Or, using \\ will do.

\\ - Insert a backslash character(\).

Upvotes: 1

Related Questions