File Transfer b/w Client - Server using JSP

Hi,
I need to implement a file transfer between the client and the server using JSP / Beans. The files can be XML Documents, Images (.gif,.jpeg) or even MS Word documents.
The user has a set directory on his file system where the files are to be saved upon download and retrieved upon upload. This system is similar to a check-in check-out system.
How do I get a reference to the directory on the users file system and then either save the downloaded files there or retrieve the files that need to be uploaded.
Thanks
coffeejava

The only way you can do this is by using an applet, a jsp page or servlet does not have access to the system that the browser is running on. Furthermore if you were planning on using the html file form object you cannot set a value for that programmatically. It's not allowed for security reasons.

Similar Messages

  • Large file transfer problems over client/server socket

    Hi,
    I wrote a simple chat problem in which I can send files from client to client. The problem is when I send large files over 101 MB the transfer freezes. I do not even get any error mesages in the console. The files I am sending are of any type (Ex mp3, movies, etc...). I am serializing the data into a "byteArray[packetSize]" and sending the file packet by packet until the whole file has been sent, and reconstructed on the other side. The process works perfectly for files smaller than 101MB, but for some reason freezes after that if the file is larger. I have read many forums and there aren't too many solutions out there. I made sure to use the .reset() method to reset my ObjectOutputStream each time I write to it.
    Here's my file sending code:
    byte[] byteArray = new byte[defaultPacketSize];
    numPacketsRequired = Math.ceil(fileSize / defaultPacketSize);
    try {
    int i = 0;
    reader = new FileInputStream(filePath);
    while (reader.available() > 0) {
    if (reader.available() < defaultPacketSize) {
    byte[] lastPacket = new byte[reader.available()];
    reader.read(lastPacket);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(lastPacket);
    output.reset();
    output.writeObject("DONE");
    output.reset();
    output.close();
    socket.close();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    else {
    reader.read(byteArray);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(byteArray);
    output.reset();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    reader.close();
    catch (Exception e) {
    System.out.println("COULD NOT READ PACKET");
    Here's my file receiving code:
    try {
    // The message from the client
    Object streamInput;
    FileOutputStream writer;
    byte[] packet;
    while (true) {
    streamInput = input.readObject();
    if (streamInput instanceof byte[]) {
    packet = (byte[]) streamInput;
    try {
    writer = new FileOutputStream(outputPath, true);
    writer.write(packet); //Storing the bytes on file
    writer.close();
    catch (Exception e) {
    System.out.println("Exception: " + e);
    else if (streamInput.equals("DONE")) {
    socket.close();
    input.close();
    break;
    catch (Exception e) {
    I'm looking for any way I can possibly send large files from client to client without having it freeze. Are there any better file transfer ways other than socket? I don't really want FTP. I think I want to keep it HTTP.
    Any suggestions would be helpful.Thanks!
    Evan

    I've taken a better look a the code you posted, and
    there is one problem with the receiving code. You
    keep repeatedly opening and closing the
    FileOutputStream. This is not going to be efficient
    as the file will keep needing to be positioned to its
    end.Yes sorry I did change that code so that it leaves the file open until completely done writing. Basically I have a progress bar that records how far along in the writing process the client is, and when the progress bar reaches 100%, meaning the file is complete, the file.close() method is invoked. Sorry about that.
    I also ran some memory tests using the "Runtime.getRuntime().totalMemory()", and "Runtime.getRuntime().freeMemory()" methods. I put these methods inside the loop where I read in the file and send it to the client. here's the output:
    Sender's free memory: 704672
    File reader read 51200 bytes of data.
    767548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 702968
    File reader read 51200 bytes of data.
    716348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 701264
    File reader read 51200 bytes of data.
    665148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 699560
    File reader read 51200 bytes of data.
    613948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 697856
    File reader read 51200 bytes of data.
    562748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 696152
    File reader read 51200 bytes of data.
    511548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 694448
    File reader read 51200 bytes of data.
    460348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 692744
    File reader read 51200 bytes of data.
    409148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 691040
    File reader read 51200 bytes of data.
    357948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 689336
    File reader read 51200 bytes of data.
    306748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 687632
    File reader read 51200 bytes of data.
    255548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 685928
    File reader read 51200 bytes of data.
    204348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 684224
    File reader read 51200 bytes of data.
    153148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 682520
    File reader read 51200 bytes of data.
    101948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 680816
    File reader read 51200 bytes of data.
    50748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 679112
    File reader read 50748 bytes of data.
    0 left to read.
    Creating last packet of size: 50748
    Last packet size after setting it equal to byteArray: 50748
    Here's the memory stats from the receiver:
    Receiver's free memory: 639856
    Receiver's total memory: 2842624
    Receiver's free memory: 638920
    Receiver's total memory: 2842624
    Receiver's free memory: 637984
    Receiver's total memory: 2842624
    Receiver's free memory: 637048
    Receiver's total memory: 2842624
    Receiver's free memory: 636112
    Receiver's total memory: 2842624
    Receiver's free memory: 635176
    Receiver's total memory: 2842624
    Receiver's free memory: 634240
    Receiver's total memory: 2842624
    Receiver's free memory: 633304
    Receiver's total memory: 2842624
    Receiver's free memory: 632368
    Receiver's total memory: 2842624
    Receiver's free memory: 631432
    Receiver's total memory: 2842624
    Receiver's free memory: 630496
    Receiver's total memory: 2842624
    Receiver's free memory: 629560
    Receiver's total memory: 2842624
    Receiver's free memory: 628624
    Receiver's total memory: 2842624
    Receiver's free memory: 627688
    Receiver's total memory: 2842624
    Receiver's free memory: 626752
    Receiver's total memory: 2842624
    Receiver's free memory: 625816
    Receiver's total memory: 2842624
    Receiver's free memory: 624880
    Receiver's total memory: 2842624
    Receiver's free memory: 623944
    Receiver's total memory: 2842624
    Receiver's free memory: 623008
    Receiver's total memory: 2842624
    Receiver's free memory: 622072
    Receiver's total memory: 2842624
    Receiver's free memory: 621136
    Receiver's total memory: 2842624
    Receiver's free memory: 620200
    Receiver's total memory: 2842624
    Receiver's free memory: 619264
    Receiver's total memory: 2842624
    Receiver's free memory: 618328
    Receiver's total memory: 2842624
    Receiver's free memory: 617392
    Receiver's total memory: 2842624
    Receiver's free memory: 616456
    Receiver's total memory: 2842624
    Receiver's free memory: 615520
    Receiver's total memory: 2842624
    Receiver's free memory: 614584
    this is just a sample of both receiver and sender's stats. Everything appears to be fine! Hope this message post isn't too long.
    Thanks!

  • How to download a file from server machine to client machine using jsp

    Hi,
    In my application, I have an excel file stored on my server machine. How can I download that excel file on to my client machine using jsp. Is there any other way I can open that file from my machine and save it in my machine using jsp/java?
    Its an emergency for me to do this.
    Can anyone provide me the full code to download a file from server machine as I don't have
    time to browse through various sites.
    thanks in advance,
    Tiijnar

    Please post your code using code tags (click on CODE above the text area, when posting)
    response.setContentType("application/octet-stream");Why octet-stream? Set the correct mime-type.
    String disHeader = "Attachment; Filename=\"filename\"";The filename should just be the file's name. Not the complete path to the file! This will tell anyone where the file is located on the server. It's also inconvenient because by default,the browser will suggest it as the name for the download.
    Your way of writing to the output stream is just plain wrong. See this snippet (picked from [http://balusc.blogspot.com/2007/07/fileservlet.html])
            BufferedInputStream input = null;
            BufferedOutputStream output = null;
            try {
                // Open streams.
                input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
                output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
                // Write file contents to response.
                byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
                int length;
                while ((length = input.read(buffer)) > 0) {
                    output.write(buffer, 0, length);
                // Finalize task.
                output.flush();
            } finally {
                // Gently close streams.
                close(output);
                close(input);
            }

  • Is it posssible to lunch one application from the client system using JSP

    Is it possible to Lunch one application from the client system using JSP or Servlet .If it is possible then how can we do that ?
    Thanks in advance
    Sil

    If its a java application - yes. You can use jnlp and web start.
    ram.

  • Can I get information regarding the client browser using JSP

    can I get information regarding the client browser using JSP. like.. name, screen resolutions, font type, screen width and height of the browser etc.,
    if possible then please give me the samples..
    thanks,

    can I get information regarding the client browser using JSP. like.. name, screen resolutions, font type, screen width and height of the browser etc.,
    if possible then please give me the samples..
    thanks,

  • How to open a file located at server using JSP

    hi,
    i would like to open a file located at server as it is. I mean to say, if it a MS Word file, i wanna open it in MS Word, if it an Excel file, i wanna open it in Excel. i know the location (path) of the file. Can someone help me please.
    Thanx

    The best way would simply be to HREF it.
    ie<a href="excelfiles/spreadsheet.xls">Open spreadsheet</a>When a user then clicks on that lick in their browser they should be given the option to either download or (if they have the appropriate program, in this case MS Excel, installed) open it.
    This works best if the client is using a version of Internet Explorer (if you're dealing with MS files), but any browser should potentially offer you the option of opening the file.
    Beyond that there's no way to specifically open a program on a client machine (it'd be a bit of a security loophole if you could! - Imagine a JSP page being able to open FDISK...). All you can do is pass the file (via the HREF) and let the client decide what to do with it.

  • How to send an attachment(file) to server using JSP

    Hello,
    I'm developing a small web-based mail system using JSP and
    JavaMail API 1.2. I need to make a compose form which allows to
    attach some file. I'm using the following HTML code:
    <FORM ENCTYPE="multipart/form-data">
    <INPUT TYPE="file" name="somename">
    </FORM>
    Would you be so kind pointing me which Java code I need to use
    to implement it.
    Thanks in advance and sorry for my English

    see the api for this:
    http://www.orionserver.com/docs/api/com/evermind/io/FilePostParse
    r.html
    you can also use this stuff:
    http://www.orionsupport.com/articles/fileupload.html
    I have found that Nick Newman's stuff is much better, though,
    since it doesn't change with the orion api (the orion api 1.5.3
    has changed, so anything you did with the above methods won't
    work with 1.5.3 ;().
    http://www.orionsupport.com/articles/downloads/UploadServlet.zip
    regards,
    the elephantwalker
    www.elephantwalker.com

  • Need PL/SQL procedure for file transfer local system to server location

    Hi Experts,
    The requirement is one file ex: text file,excel file is there in Local system suppose c:newfolder/test.txt.
    once run the concurrent program for this particular file in the local system should transfer into server location for the mentioned path.
    is it possible to do in PL/SQL or shell script.
    can you please share the code.
    Thanks
    Meher

    Meher Irk wrote:
    The requirement is one file ex: text file,excel file is there in Local system suppose c:newfolder/test.txt.
    once run the concurrent program for this particular file in the local system should transfer into server location for the mentioned path.Why do you want to copy a local file from the local client file system, via the Oracle database server, to a remote directory on the server?
    Why is the Oracle database server to be used? For what purpose?
    There are standard secure methods for a client to copy a file to a server. Such as sftp and scp. No complex Oracle database server layer needed in-between.
    So why do you want to use the Oracle database to act as the copy mechanism for you?
    It will only make sense if the local file is copied into the database (as a LOB or securefile) and managed by the database. I fail to see why Oracle should be acting as the go-between for the client file system copy process to the server file system. This introduces another moving part in the copy process. Adds more security issues. Adds more authentication issues. And what for?

  • How to read XML file kept on NON-SAP server using the Http URL ?

    Dear Experts,
    I am working on CRM2007 web UI. I need to read a XML file placed on a shared server location by a third party program. Then process that XML file into CRM and create a quotation using the data extracted from the file.
    All i have with me is the http URL that points to the location of the file.
    I am supposed to read the file , create quotation and at later point of time i would be asked to update the quotation and then generated new XML representing updated quotation and replace the XML file on shared server location with this new updated XML file.
    I know how to extract data from XML file into ABAP but i have no clue as to how to access the file on some other server using the http url i have and how to read it ?
    I searched on the forum and i found the codes for reading XML file that is located either on client machine OR on the Application server wheareas my file is on some other than sap application server.
    Please help me as its an urgent issue .
    Points will be rewarded for sure.
    Please help.
    Thanks in advance,
    Suchita.
    p.s. : the http url to the file location is like -->
    http://SomeServerDomain/SomeDirectory/file.xml

    hi,
    interesting task.
    to request the file by a http call you need to create an if_http_client object.
    More info is [here|http://help.sap.com/saphelp_nwmobile71/helpdata/en/e5/4d350bc11411d4ad310000e83539c3/frameset.htm]
    to parse the file you either have to work with the ixml packages ([info|http://help.sap.com/saphelp_nwmobile71/helpdata/en/47/b5413acdb62f70e10000000a114084/content.htm]) or you use an XSLT transformation ([info|http://help.sap.com/saphelp_nwmobile71/helpdata/en/a8/824c3c66177414e10000000a114084/content.htm]).
    uploading the final file isn't so easy. if you only have http, you should write a server script to allow uploading of the new file and copying it into the place of the old file. but you definitely need the script.
    now it's your take. depending on how experienced you are in ABAP and networking this might turn out to be easy or pretty complicated.
    have fun,
    anton

  • Downloading xls sheet from application server using jsp page

    hi,
    I am creating an excel sheet and storing it in application server which runs on HP-UNIX OS. I want to download that excel sheet using jsp page. With the following code snippet i m able to access the jsp page, but i m not able to download xls sheet. its giving "the page cannot be found "error. Is there any other way to download the excel sheet from jsp page.
    <%
    out.println("<a href=\"./Download.xls\">Download excel</a>");
    out.println("<a href=\"./Download.jsp\">Download jsp</a>");
    %>
    Thx in adv.
    ritu

    href should be ur absolure path like
    http://servername:8080/files/Download.xls"
    pls try these and let me know
    shanu

  • Removing file transfer options from client GUI.

    How do you remove all of the file transfer options from the client GUI (the button, the right-click menu option, etc.)?

    You can add <argument>allow_attachments=false</argument> in /var/opt/SUNwbsvr7/https:<hostname>/webapps/<hostname>im/en/im.jnlp file
    to disable file transfer options from the Client GUI.
    Or else if your using AM with IM then you can disable by setting the proper policy for DefaultUser through amconsole.

  • To upload excel file directly to the application server using OLE concept

    hi experts
    i have done a coding in OLE to download excel with graph to presentation server, is it possible to upload excel with graph directly to the application server  , the excel should have graph while downloading to presentation server fom app server.
    Moderator message - duplicate post locked
    Edited by: Rob Burbank on Jun 25, 2009 9:49 AM

    HI,
    have a look at tcode cg3z and then FM 'C13Z_FILE_UPLOAD_ASCII'.
    What you can do is, first create the file on presentation server using OLE automation, and then using this FM, write the file to Application server

  • Client Server using Internet [ask]

    I have a client server project who connect between LAN connection and now I want to upgrade it into internet connection. I have search several programs who has similar architecture but none is suitable. Could anybody help me out how to build basic client server which connect using internet connection?
    I have attach my previous program below, I really appreciated if anyone may modify it so be able connect trough internet.
    Solved!
    Go to Solution.
    Attachments:
    Client.vi ‏262 KB
    Server.vi ‏164 KB

    Hi,
    with your program, you seem to have the full control over your house ;-). Why it shouldn't work over internet as it is? You have TCP open, TCP close...in Internet, you simply have to use other IP-adresses as the local ones. So can you specify your question? Or is it a problem with your LAN-infrastructure, that you have to configure your router to have access from outside?
    I don't see why it shouldn't work over Inet...
    christian
    THINK G!! ;-)
    Using LabView 2010 and 2011 on Mac and Win
    Programming in Microsoft Visual C++ (Win), XCode (Mac)

  • Client-Server using RMI on Win2000

    I have a client server application using RMI that works on Win NT4.0 when I am connected
    to a network or when the it is not connected (workstation is client and server).
    This same application does not work as a standalone (not connected to network) when running
    on Win2000. I've been able to start the server (still under Win2000) by adding a Microsoft
    Loopback Adapter but the client do (can) not communicate ( see) the server(s) at all.
    Does anyone knows the difference between WinNT4.0 and Win2000 network,
    configure Win2000 for client-server on RMI loopback?
    Thanks,
    Isagani

    Yes, I did. But let me expand on the problem and observations.
    Running under Win2000 and connected to the network and working.
    - I use netstat -n (a util ) to see how my application is running when it is working.
    The port (1101) the apps uses eventually loops back to the system and the app is able
    create the multicast sockets it needs and can join the group. And everyone is happy.
    When not connected to the network, port 1101 makes a connection back to the system
    but somehow the system breaks the loop back, basically throwing an exception.
    I do not these problem with WinNT4.0
    Any ideas?
    Thanks,
    Isagani

  • How to write files on Client Machine using JSP

    Hi,
    I am new to JSP. Please tell me how do i write files on Client machine thru a Browser.
    Please let me know at the Earliest.
    Thanks.
    Mehul Dave

    1) Well I find it rather convenient to deploy a web app as just one file rather than a bunch of files. For deployment it's much better. However I prefer using expanded files when developping (to use auto reload in Tomcat for example)
    2) It is a bad idea to upload files inside your webapp's context (ie: in it's deployment directory) because one day an uninformed system administrator might come and redeploy the web app and therefore delete all your uploaded files (believe me, I've already experienced this!)
    What i do usually is upload it in a completely different directory, something like /uploaded_files. Your uploaded files are therefore completely independant from your webapp
    However it is a bit trickyer to get those files back. Let's take the example of image uploads. You have 2 ways of proceeding:
    - the easiest : configure your web server (apache etc...) to redirect a certain url to your external directory. For example the /upload url will point to a /uploaded_files directory. This is easier to do and the fastest way to serve images but not always the best solution: you are dependant on the web server's configuration and you can't control the visibility on your files (no security constraints, anyone can see your uploaded files if they know the url).
    - you can also write a servlet which will load the file as an array of bytes and send it back in the response.
    You can call it this way :
    <img src="/serlvets/showmyimage?path=uploaded.gif">
    in this way you can control your uploaded files better: you may want to define security constraints on the visibity or not of uploaded files depending on the user which has logged on the site.

Maybe you are looking for

  • Scheduling scripts and related overhead!!

    Hello All, We are in the process to make our some of the crons availability to maximum., ie it should be running all the time in case of one of our instance crash. We have two node rac cluster and we want to run our generateDailiy.sh, generateWeekly.

  • Scheduling Gantt Rendering Error

    Hi all I am having a problem while rendering a dvt scheduling gantt the error message I get is the following: bq. 10-Mar-2009 09:35:56 oracle.adfinternal.view.faces.config.rich.RegistrationConfigurator handleError \\ SEVERE: Server Exception during P

  • How to create a non-accessible script?

    I have to develop a script member that contains some procedures and functions. Is there a way to produce some "hidden" script? I think the first solution is to put this script in an external cast and protect it (AKA make it CXT). But... Is there a wa

  • Cannot display updated data in view

    I am connect to Oracle 10gR2 using SQL Developer 1.2.1 Build Main-32.13 I have a table Table_A and a sample view View_A which is "select * from table_A". Firstly, I open the Table_A and View_A in two tab. After I update the record in Table_A using Da

  • Software in Windows

    Company is using a Autodesk software, Inventor Professional 2008. We are having problem using conventional Windows based PCs. The software a resource hungry software and always take a long time to render. I am looking the possibility of using Apple c