Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

problem in uploading a file

 
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.
 
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
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
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic