File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes problem in uploading a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "problem in uploading a file" Watch "problem in uploading a file" New topic
Author

problem in uploading a file

Jatin sachdev
Ranch Hand

Joined: Jan 21, 2010
Posts: 57





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

Joined: Jan 10, 2002
Posts: 60063
    
  65

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".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60063
    
  65

And for goodness sakes, please move this code out of a JSP and put it into a servlet where it belongs.
balakrishnabilla billa
Greenhorn

Joined: Dec 17, 2008
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60063
    
  65

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

Joined: Jan 21, 2010
Posts: 57
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

Joined: Jan 10, 2002
Posts: 60063
    
  65

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

Joined: Jan 21, 2010
Posts: 57
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

Joined: Jan 21, 2010
Posts: 57
cant i use simple input sream to upload file...?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60063
    
  65

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in uploading a file
 
Similar Threads
error in uploading zip file
moving files over the network
Large File Size Upload Problem
JSP Page For Uploading a File to Destination Folder
Uploading file path in properties file