| Author |
Creating a folder in the server
|
Prabhat Kumar N
Greenhorn
Joined: Aug 12, 2009
Posts: 20
|
|
Hi there. I use Eclipse with Tomcat 6. I want to create a JSP where one can upload a file and then view it as a list of files in the directory. I have managed to accomplish upload a file to a shared folder on LAN and view it as a http page. (In server.xml of Tomcat I have context folder path to that shared folder). Now I want to make it such that anyone in across globe (not only on LAN) can create a folder there.. Any suggestions ?? The code to upload goes something like this. I got it in google search. I have done some minor corrections though. I know I must have used servlets instead. Please help.
Also, in line 25, substring is taken till '\n', but when I printed 'file' (from line 19) I could not figure out '\n' (new line) . I mean, it was like continuous chunk of information. Please tell why its used there.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
First step: move the code out of a JSP and into a servlet.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Prabhat Kumar N
Greenhorn
Joined: Aug 12, 2009
Posts: 20
|
|
Bear Bibeault wrote:First step: move the code out of a JSP and into a servlet.
Yes I know. I told that earlier. But can someone help me adjusting the code for storing in folder other than shared? I can later do adjustments for servlets.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
You'd be better served to use one of the common 3rd party libraries like Commons Upload. See the FAQ for more details.
|
 |
mark benz
Greenhorn
Joined: Aug 18, 2009
Posts: 15
|
|
Bear Bibeault wrote:You'd be better served to use one of the common 3rd party libraries like Commons Upload. See the FAQ for more details.
I agree with Bear, why would you choose to do all of the low level work where some external "tested/approved" library is made for just that.
|
 |
Prabhat Kumar N
Greenhorn
Joined: Aug 12, 2009
Posts: 20
|
|
Bear Bibeault wrote:You'd be better served to use one of the common 3rd party libraries like Commons Upload. See the FAQ for more details.
Thank you for the idea. But still I have to use, at some point of time. What location must I write here if the server is remote ? I mean, if I access the server by "http://111.111.111.111/Theloc". In the server end, in server.xml, in context, 'Theloc' is pointing to C:/Program Files of that server PC. I want to create my folder in that C:/Program Files. SO what location do I enter ? Please help.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
Where on the server do you want to write the uploaded file?
|
 |
Prabhat Kumar N
Greenhorn
Joined: Aug 12, 2009
Posts: 20
|
|
Bear Bibeault wrote:Where on the server do you want to write the uploaded file?
I told in the above post.
if I access the server by "http://111.111.111.111/Theloc". In the server end, in server.xml, in context, 'Theloc' is pointing to C:/Program Files of that server PC. I want to create my folder in that C:/Program Files. SO what location do I enter ? Please help.
I want the folder to be created in "C:/Program Files" of the Tomcat installed PC which is acting as server.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
[Please don't ninja-edit your posts]
|
 |
Prabhat Kumar N
Greenhorn
Joined: Aug 12, 2009
Posts: 20
|
|
Bear Bibeault wrote:/unsubscribes
I did not get you. I want the folder to be created in "C:/Program Files" of the Tomcat installed PC which is acting as server. I access it "http://111.111.111.111/Theloc" When I enter this I get list of directories in "C:/Program Files". "Theloc" is pointed to "C:/Program Files" in server.xml in server PC using context.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
"/unsubscribes" means I had lost all interest in the topic based upon your unwillingness to help us help you. Since you "ninja-edited" your post to answer my question, I'll give it another chance.
File I/O has nothing to do with URLs. If you want to save to a folder, simply reference the folder the same way as any other file I/O.
|
 |
Prabhat Kumar N
Greenhorn
Joined: Aug 12, 2009
Posts: 20
|
|
|
Yes. I want to reference to that folder but its like this. A client accesses the page using "http://111.111.111.111/TheLoc" and reads the list of directories pointed by 'TheLoc' ie C:\Program Files of server. In case he opens another JSP which allows him to upload a file to C:\Program Files of the server. If the location is just given as C:\Program Files will it not upload to C:\Program Files of his PC ?
|
 |
mark benz
Greenhorn
Joined: Aug 18, 2009
Posts: 15
|
|
Servlets run on the server, whatever you write in it become local to that server. As Bear referenced "File I/O has nothing to do with URLs"
btw you can use Commons file upload, and still do your new File() thing
|
 |
Prabhat Kumar N
Greenhorn
Joined: Aug 12, 2009
Posts: 20
|
|
Thank you Bear and Mark. Thats what I wanted to know
|
 |
 |
|
|
subject: Creating a folder in the server
|
|
|