file I/O on clients computer using JSP??


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: file I/O on clients computer using JSP??

  1. #1
    Join Date
    Jan 2005
    Location
    Reisterstowwn, MD
    Posts
    72

    file I/O on clients computer using JSP??

    Ok, I just started dipping into J2EE and of course have some questions. To make it short and sweet, I want to know if it is possible for a JSP page to gain any type of file access to the client's computer?
    Java has 99 problems but a pointer ain't one

  2. #2
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    Not unless you count the form-based file upload or and applet or ActiveX control embedded in the page. On the browser it's just HTML. The fact it was created by a JSP is irrelevent.

  3. #3
    Join Date
    Jan 2005
    Location
    Reisterstowwn, MD
    Posts
    72
    Yes i realize "on the browser" it is just HTML. I guess i should have worded my question better. Can the J2EE server somehow access the client's file system.. But it seems from your response this is not possible as i suspected. I thought of an applet like you mention. Correct me if I'm wrong, but can't a signed applet accepted by the client gain limited access to the client's file system? Either way, I'm looking for some way to write a simple text file to the client's computer. I would prefer to do it with some type of server-side technology rather than client-side because I don't want to have to rely on a client having a specific plugin. I guess I'm barking up the wrong tree because this if this was possible it would allow websites to place mallicious files on a client's computer. What other options do I have? Maybe have an automated email system that sends an email to the clieent with the file as an attachment?


    EDIT: Nevermind, I just thought of a solution. I could generate the file and save it on the server, and then use JSP to dynamically create a page with a link to the file. I'm guessing I have unlimited acccess to the file system on the server-side? Correct?
    Last edited by customwoodtek; 06-28-2005 at 12:54 AM.
    Java has 99 problems but a pointer ain't one

  4. #4
    Join Date
    Oct 2004
    Posts
    311
    yes, this is correct.
    You could also use a server-side redirect to redirect the client browser to the text file.

    you do this by setting the following header:
    response.setHeader("Location", "<text file location>");

    by setting this header, you tell the browser to go to that location. This redirect is done without the users knowledge, so this will be the most user friendly method.

    Another way to do it off course is to set the content type of the page to "text/plain" and to stream the text straight from the jsp page (which in the end might be easier)

  5. #5
    Join Date
    Jan 2005
    Location
    Reisterstowwn, MD
    Posts
    72
    I actually meant to write that i'm creating an XML file, not a simple text file (i'm a little out of it right now). So I cannot have any HTML or other stuff mixed in with it, therefore i need it to be a file. Anyways, it seems creating the file and then genrating a link for the client would be the best way. So I guess the last question I have is how do I go about dynamically creating the file on the server? Since J2EE is built on top of J2SE does this mean that I can simply use the file access methods that I would in a stand alone application? Or is it more complicated than that? Is it server specific? (i'm using Sun's Application Server by the way).

    Let me theorize how I think I could do it and someone tell me if this is right.

    I have a form that the user goes to. They fill out the info and hit the submit button. They are directed to a JSP page that pulls the information and places it inside a java bean, this bean is then passed to a class I made that creates the XML file on the server (using typical file access as i would in a stand alone app, specifically the java.io classes). The JSP page also provides a link to the newly created file allowing the user to download it.

    Someone point me in the right direction here. Thanks for the help.
    Java has 99 problems but a pointer ain't one

  6. #6
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    It depends on your design of course but you don't have to create a file at all. You can create the xml doc in memory and stream that out to the browser either as the response to the form submission or as a link to a servlet on the form response page.
    Code:
    Form->(request)servlet->(response)xml stream
    
    or
                               /-->(session)bean---------------------\
    Form->(request)servlet->(response)page w/link->(request)servlet->(response)xml stream

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center