Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in uploading a file

 
Jatin sachdev
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





This particular code is uploading the file at /bin folder of tomcat server, but i want this to upload in webapps. i can't understand how it is storing in /bin. please suggest some solution.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are likely using a relative file path to specify the file location. That will put the file some non-deterinistic place as web apps have no concept of "current directory".
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And for goodness sakes, please move this code out of a JSP and put it into a servlet where it belongs.
 
balakrishnabilla billa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
please give the correct path where you wanted to create a file in server.
here i given a sample code here

before use, please remove the read only permissions to the web apps folder.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
balakrishnabilla billa wrote:please give the correct path where you wanted to create a file in server

But, of course, hard-coding the path as a string would be a very bad practice indeed.

Rather, determine the location programmatically.

Also, do you really want to upload a file into the web app? Really? What happens when you have to redeploy and update?
 
Jatin sachdev
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for suggestion..............

But as Bear has said
do you really want to upload a file into the web app? Really? What happens when you have to redeploy and update?


where should i upload the file then...?
One more thing i want to ask --- Is there any easy code that i can understand and works accordingly for uploading file?
i dont know actually how to upload file....
please help and give some code snippet for uploading a file....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JSP FAQ where file uploads are discussed.

With regards to where to put it, what is the purpose of the file?
 
Jatin sachdev
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
purpose of the file is to authenticate the user on the basis of some information in the file.
I have searched JSP FAQ but the link provided :

On the client

If you want to upload files in conjunction with Commons HttpClient, this introductory article tells how to use FileUpload in conjunction with the Commons HttpClient package.


is not working.............
 
Jatin sachdev
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cant i use simple input sream to upload file...?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jatin sachdev wrote:cant i use simple input sream to upload file...?

The input stream contains a multipart request which is a pain in the rear to parse. No one in their right mind would try to reinvent the wheel when a number of perfectly good libraries that have already solved the problem exist.

Why do you need to write a file to authenticate a user?U
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic