How to save a file in client system?

I have a requiremnet like this:
"When the user selects a file from his local drive (say c:\), I have to upload the file to a LAN connected to his machine."
I have written the TestUpload class like below. It will work if my server is on the same machine. But, how can i do this if it is Unix Server?
I was trying to do this for 2-3 days. Please help.
protected void doGet(
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
HttpSession session = null;
UploadListener listener = null;
long contentLength = 0;
System.out.println("I am inside doGet");
if (
((session = request.getSession()) == null) ||
listener =
(UploadListener) session.getAttribute("LISTENER")
) == null
) || ((contentLength = listener.getContentLength()) < 1)) {
out.write("");
out.close();
return;
response.setContentType("text/html");
long percentComplite =
((100 * listener.getBytesRead()) / contentLength);
out.print(percentComplite);
out.close();
protected void doPost(
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
// create file upload factory and upload servlet
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// set file upload progress listener
UploadListener listener = new UploadListener();
HttpSession session = request.getSession();
session.setAttribute("LISTENER", listener);
// upload servlet allows to set upload listener
upload.setProgressListener(listener);
List items = null;
FileItem fileItem = null;
String filename = null;
String fileName = null;
String directory = null;
String version = null;
String fullPath = null;
String extension = null;
String folderName = null;
try {
// iterate over all uploaded files
items = upload.parseRequest(request);
for (Iterator i = items.iterator(); i.hasNext();) {
fileItem = (FileItem) i.next();
System.out.println("New file Item::: " + fileItem.getName());
if (
(fileItem.getName() != null) &&
!fileItem.getName()
.trim()
.equals("")) {
fullPath = fileItem.getName();
extension = fullPath.substring(fullPath.lastIndexOf("."));
directory = "\\\\MyLAN\\";
fileName =
fullPath.substring(
fullPath.lastIndexOf("\\") + 1,
fullPath.lastIndexOf("."));
folderName = getFolderName(directory, fileName, extension);
version =
getVersionNumber(
directory + folderName, fileName, extension);
String strFilePath =
directory + folderName + fileName + version +
extension;
System.out.println("path:: " + strFilePath);
          //Creating the destination File object.
File file = new File(strFilePath);
if (!fileItem.isFormField()) {
if (fileItem.getSize() > 0) {
// code that handle uploaded fileItem
// don't forget to delete uploaded files after you done with them! Use fileItem.delete();
fileItem.write(file);
fileItem.delete();
                                   System.out.println("upload successful");
// indicate that the upload was successfull
writeLog(
directory + folderName + "log.txt",
now() + " ::: " + "Uploaded the version number:: " + version);
response.getWriter()
.write("upload successful");
} catch (FileUploadException e) {
response.getWriter()
.write(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
response.getWriter()
.write(e.getMessage());
e.printStackTrace();
} finally {
session.removeAttribute("LISTENER");
public String getFolderName(
String directory, String fileName, String extension) {
File dir = new File(directory);
boolean folderFound = false;
String foldername = null;
String logFileName = "";
File getFolderNames[] = dir.listFiles();
for (int i = 0; i < getFolderNames.length; i++) {
foldername = getFolderNames.getName();
if (foldername.equalsIgnoreCase(fileName)) {
folderFound = true;
break;
if (!folderFound) {
File f = new File(directory + fileName);
f.mkdir();
f = new File(directory + fileName + "/log.txt");
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
logFileName = directory + fileName + "/log.txt";
writeLog(logFileName, "***********************************");
writeLog(logFileName, "Log for the file " + fileName);
writeLog(logFileName, "***********************************\n\n");
writeLog(logFileName, now() + " ::: " + "Created");
return fileName + "\\";
public String getVersionNumber(
String directory, String fileName, String extension) {
File dir = new File(directory);
boolean fileFound = false;
int version = 0;
File getFolderNames[] = dir.listFiles();
version = getFolderNames.length;
return "_" + version;
public void writeLog(String fileName, String text) {
try {
Writer output = null;
File file = new File(fileName);
output = new BufferedWriter(new FileWriter(fileName, true));
output.write(text + "\n");
output.close();
System.out.println("Log file has been written");
} catch (IOException e1) {
e1.printStackTrace();
Edited by: AnishThomas on Mar 12, 2008 10:52 PM

Thanks for your reply!!!
jwenting wrote:
no, your code is NOT correct.
It doesn't "upload" anything, as I stated before.It is working perfectly fine if the destination folder is connected to the server machine (which is not the case now).
>
Look into multipart MIME requests, Jakarta Commons File Upload, and things like that to actually upload files to a server instead of insisting on reading them directly from the client's filesystem in your servlet and wondering why that doesn't work if the servlet container is running on a different computer from the client.I AM using Jakarta Commons File Upload. The problem is when I try to access the destination folder(which is in client machine), it can't find as it is searching for the corresponding folder in the server.
>
Unless and until you do that, you're wasting our time and your own.I thought someone could help me i giving me some pointers which I missed. Thanks again!!
Edited by: AnishThomas on Mar 14, 2008 8:13 AM

Similar Messages

  • How to create Excel file in client system...

    please tell me,
    how to create a excel file in the client system. in my application i am displaying the report from database. my requirement is to create that report in excel format that should be stored in client machine...

    http://jakarta.apache.org/poi/
    One of the best solution.....

  • How to print html file on client system without viewing data on client syst

    I want to print html data from database.
    i am not able to print it using java code,
    javascript can do that.
    but in javascript window is opened on client browser.
    but i dont want to open that
    var disp_setting="toolbar=no,location=no,directories=no,menubar=no,";
           disp_setting+="scrollbars=no,width=0,height=0";
         var docprint = window.open("","",disp_setting);
         //docprint = new PopUpWindow() ;
         docprint.document.write('<%= mm %>');
         docprint.document.close();
            docprint.focus();
         docprint.document = null; mm contents the data to be printed. it prints well but window is shown
    in mm there is <BODY self.print() > so it prints on printer but i am viewing window i donot want to view window....
    and print Dialog box also.. I want to by pass this both.
    please send me code or any help regarding that.
    ....

    1. Post a javascript question on a javascript forum please.
    2. Don't think you can bypass without some plugin/setting on the client browser.

  • How to save pdf file in database

    Dear All,
    my application is forms 6i and database is 8i,requirement is that how to save pdf file in database and users can view through forms

    I'll apologize up front for the length of this post. I have a few database procedures I created that write a file to a BLOB column in a table as well as retrieve the BLOB from the column after it stored there. I have successfully stored many different types of binary file to the database using these procedures - including PDF files. I have not used these procedures in a Form so I can confirm that they will work, but theoretically they should work. I'm including the code for each procedure in this posting - hence the apology for the long post! :-)
    Also, since these procedures reside on the database you will need to use Forms TEXT_IO built-in package to write your file to the server before you can use these procedures to store and retrieve the file from the database.
    These procedures reads and writes a binary file to a table called "LOB_TABLE." You will need to modify the procedure to write to your table.
    -- Author :  Craig J. Butts (CJB)
    -- Name   :  load_file_to_blob.sql
    --        :  This procedure uses an Oracle Directory called "IN_FILE_LOC".  If you
    --           already have a directory defined in the database or would prefer to use
    --           a different Directory name, make sure you modify line 21 to reflect the
    --           new Directory name.
    -- ==================================================================================
    -- History
    -- DATE        WHO         DESCRIPTION
    -- 12/11/07    CJB         Created.
    CREATE OR REPLACE PROCEDURE load_file_to_blob (p_filename IN VARCHAR2) IS
       out_blob    BLOB;
       in_file     BFILE;
       blob_length INTEGER;
       vErrMsg     VARCHAR2(2000);
    BEGIN
       -- set the in_file
       in_file := BFILENAME('IN_FILE_LOC',p_filename);
       -- Get the size of the file
       dbms_lob.fileopen(in_file, dbms_lob.file_readonly);
       blob_length := dbms_lob.getlength(in_file);
       dbms_lob.fileclose(in_file);
       -- Insert a new Record into the tabel containing the
       -- filename specified in P_FILENAME and a LOB_LOCATOR.
       -- Return the LOB_LOCATOR and assign it to out_blob.
       INSERT INTO lob_table (filename, blobdata)
          VALUES (p_filename, EMPTY_BLOB())
          RETURNING blobdata INTO out_blob;
       -- Load the file into the database as a blob.
       dbms_lob.open(in_file, dbms_lob.lob_readonly);
       dbms_lob.open(out_blob, dbms_lob.lob_readwrite);
       dbms_lob.loadfromfile(out_blob, in_file, blob_length);
       -- Close handles to blob and file
       dbms_lob.close(out_blob);
       dbms_lob.close(in_file);
       commit;
       -- Confirm insert by querying the database
       -- for Lob Length information and output results
       blob_length := 0;
       BEGIN
          SELECT dbms_lob.getlength(blobdata) into blob_length
            FROM lob_table
           WHERE filename = p_filename;
       EXCEPTION WHEN OTHERS THEN
          vErrMsg := 'No data Found';
       END;
       vErrMsg := 'Successfully inserted BLOB '''||p_filename||''' of size '||blob_length||' bytes.';
       dbms_output.put_line(vErrMsg);
    END;
    -- Author   :  Craig J. Butts (CJB)
    -- Name     :  write_blob_to_file.sql
    -- Descrip  :  This procedure takes a BLOB object from a database table and writes it
    --             to the file system
    -- ==================================================================================
    -- History
    -- DATE        WHO         DESCRIPTION
    -- 12/11/07    CJB         Created.
    CREATE OR REPLACE PROCEDURE write_blob_to_file ( p_filename IN VARCHAR2 ) IS
       v_blob      BLOB;
       blob_length INTEGER;
       out_file    UTL_FILE.FILE_TYPE;
       v_buffer    RAW(32767);
       chunk_size  BINARY_INTEGER := 32767;
       blob_position INTEGER := 1;
       vErrMsg     VARCHAR2(2000);
    BEGIN
       -- Retrieve the BLOB for reading
       BEGIN
          SELECT blobdata
            INTO v_blob
            FROM lob_table
           WHERE filename = p_filename;
       EXCEPTION WHEN OTHERS THEN
          vErrMsg := 'No data found';
       END;
       -- Retrieve the SIZE of the BLOB
       blob_length := DBMS_LOB.GETLENGTH(v_blob);
       -- Open a handle to the location where you are going to write the blob
       -- Note:  The 'WB' parameter means "Write in Byte Mode" and is only
       --          available in the UTL_FILE pkg with Oracle 10g or later.
       --        USE 'W' instead for pre Oracle 10q databases.
       out_file := UTL_FILE.FOPEN('OUT_FILE_LOC',p_filename, 'wb', chunk_size);
       -- Write the BLOB to the file in chunks
       WHILE blob_position <= blob_length LOOP
          IF ( ( blob_position + chunk_size - 1 ) > blob_length ) THEN
             chunk_size := blob_length - blob_position + 1;
          END IF;
          dbms_lob.read(v_blob, chunk_size, blob_position, v_buffer );
          UTL_FILE.put_raw ( out_file, v_buffer, TRUE);
          blob_position := blob_position + chunk_size;     
       END LOOP;  
    END;Hope this helps.
    Craig...
    -- If my response or the response of another is helpful or answers your question please mark the response accordingly. Thanks!

  • HELP!!!! How to save xml file!!!Anyone can help???

    Hi,
    It is urgent for me to know how to save xml file. I use VC++6.0, Oracle xdk 9.0.0.0.0 or 9.0.0.0.0Abeta under windows98.
    It is OK to compile the program with print() method. But system will tell me there is illegal operation when I run it. If I delete the line with print(), the result will be normal.
    in class node, there is two functions
    void print(ostream *out = &cout, uword level = 0,uword step = 4);
    void print(DOMString buffer, size_t bufsize, uword level = 0, uword step = 4);
    Is there anyone who may tell me how to use them? to write back specific xml file?
    Without print(), I can not save the xml file...It seems in Oracle xdk9.0.0.0.0, there is no obvious function to save the file.(or because I am a new comer , not familier with DOM)
    Can anyone tell me how to save xml file? or just paste an example! It is very a little urgent to me...Hope you give me some ideas....
    Many thanks in advance!!!!
    yours,
    Fiena

    Hi,
    goto sxmb_adm > intergration engine configration > specific configration
    go in edit mode > new entry
    choose
    Category -> IDoc
    Parameters -> XML_CONVERSION
    current value -> 2
    Regards,
    Manisha

  • Could u plz help me to find simple example for how to save data file in a spread sheet or any other way in the real time controller for Sbrio 9642 using memory or usb flash memory

    Could u plz help me to find simple example for how to save data file in a spread sheet or any other way in the real time controller for Sbrio 9642 using memory or usb flash memory

    Here are a few Links to a helpful Knowledge Base article and a White Paper that should help you out: http://digital.ni.com/public.nsf/allkb/BBCAD1AB08F1B6BB8625741F0082C2AF and http://www.ni.com/white-paper/10435/en/ . The methods for File IO in Real Time are the same for all of the Real Time Targets. The White Paper has best practices for the File IO and goes over how to do it. 
    Alex D
    Applications Engineer
    National Instruments

  • How to save CSV file in application server while making infospoke

    How to save CSV file in application server to be used as destination while making infospoke.
    Please give the steps.........

    Hi
    If you want to load your flatfile from Application server,then you need to trasfer your file from your desktop(Computer) to Application server by using FTP.
    Try using ARCHIVFILE_CLIENT_TO_SERVER Function module.
    You Just need to give thesource path and the target path
    goto SE37 t-code , which is Function module screen, give the function name ARCHIVFILE_CLIENT_TO_SERVER, on click F8 Execute button.
    for path variable give the file path where it resides like C:\users\xxx\desktop\test.csv
    for target path give the directory path on Application server: /data/bi_data
    remember the directory in Server starts with /.
    U have to where to place the file.
    Otherwise use 3rd party tools to connect to ur appl server like : Core FTP and Absolute FTP in google.
    Otherwise...
    Goto the T.code AL11. From there, you can find the directories available in the Application Server.
    For example, if you wanna save the file in the directory "DIR_HOME", then you can find the path of the directories in the nearby column. With the help of this, you can specify the target path. Specify the target path with directory name followed by the filename with .CSV extension.
    Hope this helps
    regards
    gaurav

  • Does anyone know how to save a file in CC 10.0 or higher that is viewable in CC 9.2?

    I am trying to make my fiels viewable to someone who has Adobe CC version 9.2, but I have version 10.0. Does anyone know how to save my files so the are readable?

    You will likely get better program help in a program forum
    The Cloud forum is not about using individual programs
    The Cloud forum is about the Cloud as a delivery & install process
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • How to save iPhoto file in a separate portable hard disk drive?

    How to save iPhoto file in a separate portable hard disk drive?

    You want to move the iPhoto Library?
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Regards
    TD

  • How to extract  DB  FILE  FROM NONSAP  SYSTEM  IN BI-7

    how to extract  DB  FILE  FROM NONSAP  SYSTEM  IN BI-7

    hi,
    chk the links for extraction using DB
    Extraction using DB connect
    http://help.sap.com/saphelp_nw70/helpdata/EN/58/54f9c1562d104c9465dabd816f3f24/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/c6/0ffb40af87ee6fe10000000a1550b0/frameset.htm
    Extract data from oracle DB to SAP BI 7.0
    Ramesh

  • How to save Numbers file as Excel (XLSX) file ?

    I just want to know how to save Numbers files into Excel format. Because other than Mac users can't able to access Numbers format.

    File, Export To, Excel…

  • How to save psd files...

    how to save psd files so other can change (with all fonts and Layers)
    I need to know how to save everything in the psd so others still can use it.??

    Hi,
    If you have photoshop and you are working on it and have used layers , fonts , and other things
    Then after completing your work, click save and it will open save Box,
    make sure the file format in the box should be PSD and then you may save the file and then you can share with any one.
    Any one who has Photoshop will be able to open that file and can edit the layers and fonts..
    --Baljeet

  • How to save .pdf file using office word and excel

    Can someone help me how to save .pdf files using office word and excel?  I reinstalled my adobe 7.0 pro in my new pc and before I was able to do it but with my old pc.

    For anything after Office 2003, you have to print to the Adobe PDF printer. If you installed AA 7 on OS newer than XP, you may have to do a workaround to get it to work. With later versions of WORD you can always use the MS plugin for creating PDFs.

  • How to save image files into SQL Server?

    Hello, All:
    Does anyone know how to save image files into SQL Server? Does the file type have to be changed first?? Please help me! Thank you!

    You need a BLOB field (usually)... Then you can check this tutorial out:
    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBPut/
    There are other exercises on that site, including one on reading the images back.

  • How to Import Transport Files to SAP System

    Hi Experts,
    I have installed BO XI R3.1 SP3 Integration tool kit for SAP Solutions with Java Connectors.Now i can able to see SAP after login into the CMC. I have installed prerequisites like SAP GUI,Xcelsius,BO XI 3.1 Enterprise.
    1)Can you please tell me how to import transport files to SAP System?So that i can connect to BW to Bo environment.I am unable to understand the process to do above task form pdf.

    Hi Venkat,
    in case you have never done that before I would suggest you talk to the basis admin person and let him do it.
    ingo

Maybe you are looking for

  • Firefox won't open external links (from other programs), says its already running but not responding.

    I'm having this problem, everytime i click a link on other program, like the program's link on the about tab, or a youtube link on Live Messenger, it won't open, a dialog pops up saying firefox is already running and not responding, but it is there,

  • Why can't I print embedded images in a Thunderbird E-mail? I just get blank boxes for the images.

    I am a copyeditor who receives feedback from my clients re: manuscripts I have edited. They will often sent e-mails that include small screen captures from parts of their style guide or screen captures of the proof that is in question (small sections

  • Hard Drives not mounting

    Hi there...I have a QuickSilver 2001 G4 Tower with two internal 60GB HD and one External Wester Digital 120 GB HD which is my boot drive. For a few weeks my internal hard drives would sometimes mount and sometimes not. Now they completely are not sho

  • DispatchEvent

    I'm modeling an application after the ReviewTube sample application. That application the following class defined. I wrote a class almost identical to this and I get an error "1180: Call to a possibly undefined method dispatchEvent." on the line with

  • Skype for Business edition Download?

    Hi, I'm looking for the special business version for skype which is configure in a msi installer file. I'm not able to find it anywhere in the skype website not even in skype for business or Skype Manager web console. as an IT Administrator i need to