Java Queries Here..

Piyush

Lanaya
Yup I did the XML part. Sorry that I didnt replied to that post since I was stuck on this issue.

And again, my bad, for not explaining the complete scenario. So here it is:

Our group is making a complaint mgmt system based on jsp/jquery and oracle db. We have already done the login / session part. My task was to allow files to get uploaded to the server, which later can be viewed/delete by the admin. So we were discussing that what we can do is, when a remote user clicks on "upload" button to upload a file, a folder should be created on our machine with his name and the file should go there.
This way we can maintain a clean record of all the files from various users. And just to mention, all users have different names, that we have checked since we already have the complete db of the users name and related info.

----------------------------------------------------------------
I searched a bit . There's a method mkdir() in java which can create a folder. Can this help me?
 

vickybat

I am the night...I am...
^^ You can achieve this using regular file handling in java.

A little google gave me this:

jsp - how to create a folder in tomcat webserver using java program? - Stack Overflow

I think you can figure out from here.
 

Piyush

Lanaya
Thanks man I'll post here when I complete this task
Just one more query. I'm using Tomcat 6.0.35 I think. There wont be much difference na between my tomcat and that guy's 7.0 version?
 
OP
furious_gamer

furious_gamer

Excessive happiness
Thanks man I'll post here when I complete this task
Just one more query. I'm using Tomcat 6.0.35 I think. There wont be much difference na between my tomcat and that guy's 7.0 version?

If there is any version-specific thing he did, it may be an issue. Otherwise no issues....

Thanks man I'll post here when I complete this task
Just one more query. I'm using Tomcat 6.0.35 I think. There wont be much difference na between my tomcat and that guy's 7.0 version?

If there is any version-specific thing he did, it may be an issue. Otherwise no issues....
 

Piyush

Lanaya
Back again. Did some part, stuck on some.
I'm able to upload file and save it in a folder. Connected the code with database . But the thing is, I'm confused now.
I am not aware of the methods/classes which can be helpful in creating folder dynamically according to the name stored in db/ user name of the user uploading at remote machine.

So I'l explain again my sequence of tasks:

1. User clicks on upload button (user on a remote machine using app on our server)
2. Uploads the file and gets the message of successful upload.
3. At our side, a folder is created with his name and his file is saved in the folder. (Note: We have lists of users who will be using app, so that means we do have the usernames/userid)

Till now I'm only able to finish 2 steps, last step is bugging me since 3 days now.

Update:
Found a other way out. I just appended the current date-time before the file name so as to maintain unique file names . Was so depressed (in IT lingo) :evil:
 
OP
furious_gamer

furious_gamer

Excessive happiness
Instead of giving user names as folder names, you better hash his name, get some random code like md5. This way folder names will be unique and safe. Only way you can access the folder is, again hash the name with md5.
 

Piyush

Lanaya
Instead of giving user names as folder names, you better hash his name, get some random code like md5. This way folder names will be unique and safe. Only way you can access the folder is, again hash the name with md5.
I dont know how to implement hash codes.
Also, again back to the square one. We have to implement this with the help of separate folders instead of appending date and time.

Thing is, our Director sir wants it this way because, we will be able to easily check and maintain the uploaded attachments. Separate folders for different labs will be helpful when there are like 56 labs. So ya, I agree on their opinion.

So guys..... guide.
 
OP
furious_gamer

furious_gamer

Excessive happiness
That is what i am telling..

For ex, you have 56 labs with name like lab1,lab2 .... etc

So, hash the string "lab1" will give you something like 109kajskjaw9uwqsjjs9i. And goes on for lab2, lab3 etc.

So next time, you want to access lab14 folder, all you need to do is, hash the lab14 again with one-way hashing and voila, you have the folder name. Got it?
 

Piyush

Lanaya
That is what i am telling..

For ex, you have 56 labs with name like lab1,lab2 .... etc

So, hash the string "lab1" will give you something like 109kajskjaw9uwqsjjs9i. And goes on for lab2, lab3 etc.

So next time, you want to access lab14 folder, all you need to do is, hash the lab14 again with one-way hashing and voila, you have the folder name. Got it?

Oh you mean that hash will give each lab a certain unique ID which can be used to get the lab name itself? It sounds good, but I have no idea how will I implement it (will have to learn) and whether it will be easy to implement it.
 
OP
furious_gamer

furious_gamer

Excessive happiness
See this link : Java MD5 Hashing Example

There, you pass the labname and it will give md5 digest. And you create folder with the obtained digest.
 

Piyush

Lanaya
I was not able to implement it properly so left it.
Anyway, my problem is all fixed now.

New task:
I want to restrict the file type when uploading, like only pdf/txt/rtf/jpg files.
I cant use "accept" attribute since there will be many people who must be having IE 7/8/9. So I need other way out.
 
OP
furious_gamer

furious_gamer

Excessive happiness
^^ You can do it at client-side. You can read the file name from file-input field. Check last "." and get the extension. After that, put an conditional statement and restrict.

Example Link : SOF
 

Piyush

Lanaya
One more:

I want to set a session expiry condition. And I want to do it via jsp only.
I searched a bit but Filter class was the only solution I found but it needs a proper servlet which I dont wanna do.
Anything there to help here via JSP?
 
OP
furious_gamer

furious_gamer

Excessive happiness
Always the best way to keep session expiry part, is Servlet. You can do simple session expiry condition on top of JSP page.

Ex :

if(session.getAttribute("userid")==null)
out.print("Session expired");
else {
// The whole JSP content goes here....
}

OR

if(session.getAttribute("userid")==null) {
//Redirect to any page you want.
}

But seriously, go with Servlet and Filter.
 
Top Bottom