4

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

sathya
  • 1,404
  • 2
  • 15
  • 26

3 Answers3

3

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.

Aryan
  • 1,767
  • 2
  • 22
  • 39
1

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?

Community
  • 1
  • 1
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
  • Maybe show some code and I can be more specific. JSP should be used to show the View to your user on the browser. When data is POSTED (submitted / file uploaded) it should be sent to a servlet running in a Java Application Server like Tomcat. The users browser (maybe 100's of users) will be running on a different machine to the servlet. – Scary Wombat Mar 31 '14 at 08:02
  • JSP is not client side code, JavaScript, HTML, CSS are. – Alexandre Lavoie Mar 31 '14 at 09:46
  • I have edited my answer to (whilst trying to keep it easy) explain the differentiation of the use of JSP vs Servlet code – Scary Wombat Apr 01 '14 at 00:11
  • @Java1 I want to upload it. if i have path.. i pass it as a String to servlet and easily i upload it.. If you know how to pass file to servlet from jsp? – sathya Apr 03 '14 at 10:50
  • @AlexandreLavoie I do not think I ever said that JSP was client code. I said that it produces HTML code. – Scary Wombat Jun 05 '14 at 02:56
0

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.

developerwjk
  • 8,619
  • 2
  • 17
  • 33