Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Help in java

  Asked By: Leon    Date: Sep 21    Category: Java    Views: 994

I'm writing an app in which clients can share their files(on their own drives) with others.
The users can interact with the app, via the browser.
the webApp part is written in JSP.

When a client submit a query for a file, the server(which has metaData of files and their location), send the results(and a link to retreive each of them) back to client.

I want my client's be able to download or view the files, by clicking the given link.

The network is a LAN, and the files're stored on client machines, not the server!
and the files can be of any types.

Is there a way for me to do this?



7 Answers Found

Answer #1    Answered By: Dot net Sachin     Answered On: Sep 21

Just give a link  to the file  !and dont forget to set
the getMimeType() servletContext

Answer #2    Answered By: Renee Lane     Answered On: Sep 21

u mean i give a link, like "\\client'sMachineName\filePath" ?
and it will work !?
I am new in JSP...
And I have several questions ...
1) does this link  "\\machineName\filePath" work at all? (with this exact format)
you know, i don't have a lan, so I can't test it myself.
2)if yes, should i do some thing to view  the file, or it just work?
you know, Only the files  in web root directory, can be viewed , with a link.
i tried to view a pdf file  (not locted on root directory), and it didn't work!
So, should i write a script for it?
3) if yes, where can i find one?

I am in a Very Big Trouble with my BS project!
And I don't have enough time :(
Could U PLZZZZZZ help  me?

Answer #3    Answered By: Volney Fischer     Answered On: Sep 21

I think this will help  you.

You have a web server, e.g. Tomcat (Your servlet
container). You have deployed your web application
into ${tomcat.server.dir}/webapps/MyWebApp
Your files  should be web accessible. It means you
should put them into a directory on the server in your
web application dir.

Now you can give a link  to this file. Your web address
to these files is something like this:


Consider that when you act this way, one can access
these files directly using this address:

Answer #4    Answered By: Sophie Campbell     Answered On: Sep 21

I think the easiest way is to create a share  directory
on the same server that you are going to deploy your
web applications.
Let say that the URL of you site is www.yoursite.com
if everybody upload his/her files  to the same place
then you can create link  in your JSP page such as

Answer #5    Answered By: Adalwine Fischer     Answered On: Sep 21

The solution which is given by Mr. farzad maybe work
when the files  are under your web application
directory and if you don't use war or ears because
you can not access out of the web application
directory where you normally place your jsps htmls or
images. So if you want to really create a file
accessing facade for your web application which allows
to browse a directory and it subdirectory you must
create a servlet which facilities this purpose you can
define your root directory as context-parameter in the
web.xml and then the developed servlet (which you must
write it) use these parameter to find the real
location of the files and directory.

First your servlet must show the directory content of
the specified root directory by means of java.io.File
class facilities(especially its list() method) and
provide a link  for each item in the directory (you can
add more images if you want to have more user-friendly
UI bit your servlet can generate a simple list of

Every time that user selects a file  from this page a
new GET request must be sent to the servlet which
contains the relative path of the selected file
The servlet then must use this relative path in
combination of the root path specified in web.xml to
locate the real location  of the file or directory
Then you can use File class facilities to determine
whether use selected a folder or file <<java.io.File
's isDirectory() method)(Keep in mind that you don't
need to provide the type of case in your page as its
link parameter because system can found it only by
means of its name!)
if the selected case is a file you can use the
HttpServletResponse facility like getOutputStream to
write the content of it in the response object but
before writing  the content you must set the content
type of the response properly by any means that you
can support (for example by using the extension of the
file or self detection that java  utilities provide).
And in the case of the directories you can simply list
the content of it again by means of File facilities as
described above for showing root content.

Answer #6    Answered By: Kristin Johnston     Answered On: Sep 21

Did you consider that your web application may be war
or ear and your web app  server doesn't allow putting
many different materials in its web! So it's nice to
take any easy but may be its better to anticipate the
effects! You and another friend are fans of direct
directory accessing (Shared directory) but Do you now
by means of this approach you allow that everyone
access your server life! If certainly these approaches
work well there is no need to developed applications
which provides FTP facilities in themselves!

So I provide my approach as a student project not as a
comprehensive or even complete and best solution so
you must consider the conditions and need of Software!
Althogh I think that in any condition I will not
suggest file  sharing or putting files  in the web
application directory for this purpose!

Answer #7    Answered By: Beatriz Silva     Answered On: Sep 21

I'm not sure but as I understood she deal with distributed files  and she want to create a web app  on the server as a proxy to access them by using metadata's.

So there are two things that should be considered:

1- the way you use to generate metadata's

2- access method

The first one is more important but it's completely depends on second. But the second is your question and for this, the simplest way, as someone else mentioned is using of this format: \\machinName\dirName\fileName .when those files are shared (by enough permission) but this approach is completely platform dependent and it lacks many things. But this is enough for your project J

Don't worry about "war" or "ear" because just dynamic resource (such as Servlets) must be placed under your web app root and the web server itself handles the rest.

Didn't find what you were looking for? Find more on Help in java Or get search suggestion and latest updates.