Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I get a file from client,and read it?

 
chenw
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I make an applet,and use "FileDialog" class to choose a file and send its path to my servlet.When a client choose a file and sent its path to my servlet,why does my servlet search his file at my computer but not at his computer?
What shall I do? Should I get the URL of his file?
 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
When the file path reaches the servlet, for the servlet this path is relative to the servlet directory or the root directory in the same system.The servlet cannot access the client's system.So you cannot make the servlet read any client's file on its own. However you have two ways:
1. Make the applet trusted(by third party) so that it can read any client's file directly and send the contents to the servlet. For the servlet the file content will simply be a data stream sent by the applet.
2. Use the HTML file upload: <INPUT TYPE=FILE> to upload the file to the servlet.For this you might want to read a good book: Java Servlet Programming-OReilly.
hope this helps
Tanveer
 
chenw
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for your answer.Could you tell me how to make the applet trusted in details?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic