sathya
sathya

Reputation: 1424

how to get full path for upload a file in jsp?

In my jsp page, use file uploading and pass file for string to java page for copy to particular folder. I want whole path for copying my file. but i get only a file name with extension.

scan file : ABC.pdf

it show only : ABC.pdf

i want to show: c:/abc.pdf

Upvotes: 4

Views: 35852

Answers (3)

Scary Wombat
Scary Wombat

Reputation: 44834

JSP is code that produces the client facing HTML code (commonly called the View) and the Servlet is server code. In reality they will be on different machines, so what is the use of the full path. The file contents should be POSTED to the servlet when submitting your form.

your jsp should something like:

<form action="UploadServlet" method="post"
                        enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>

Of course you have other input fields as well.

See this link

How to upload files to server using JSP/Servlet?

Upvotes: 1

developerwjk
developerwjk

Reputation: 8659

The Local filepath is useless on the server-side. It would only be of use to hackers. That's why browsers don't send it. Its a security measure. You should be glad its there. I'm surprised none of the existing answers pointed this out.

On the server-side you decide where to save the file. You wouldn't want the user deciding that, obviously. Giving them the ability to decide where to save the file on your server would give them the ability to overwrite your system files.

Upvotes: 0

Aryan
Aryan

Reputation: 1877

JSP is indeed a Server side technology. Here are few of the links to do a file upload using JSP.

http://www.tutorialspoint.com/jsp/jsp_file_uploading.htm

http://corejavaexample.blogspot.in/2013/04/how-to-upload-file-in-jsp.html

http://javarevisited.blogspot.in/2013/07/ile-upload-example-in-servlet-and-jsp-java-web-tutorial-example.html

Hope this may help solve your issue.

Upvotes: 3

Related Questions