How to upload file from a client machine to server machine

hei evryone!
can anyone pls help me on how i can upload file from a client machine to another machine (or server). using jsp.Then later on, i can also retrieve the names of these files to place it as values for option tag in an html form.I have a seperate screen for uploading the file and the screen for displaying all the files that were uploaded on the server...
any sample code/ ideas would be much appreciated.Thx!!!!

hei evryone!
can anyone pls help me on how i can upload file from a client machine to another machine (or server). using jsp.Then later on, i can also retrieve the names of these files to place it as values for option tag in an html form.I have a seperate screen for uploading the file and the screen for displaying all the files that were uploaded on the server...
any sample code/ ideas would be much appreciated.Thx!!!!

Similar Messages

  • How to upload file from java client to php

    hi
    i am trying to upload/send a file from client using swing/applet
    and receiving it with php code.
    here is the php code which uploads the post file from the client
    $uploaddir = "/home/raghavendra/Documents/";
    $file = basename( $_FILES["uploadedfile"]["name"]);
    echo "file:\n".$file;
    $uploadfile = $uploaddir. $file;
    if (move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],$uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
    else {
    echo "File upload failure Possible file upload attack!\n";
    and corresponding different java code which post the
    1)
    public void postmethodTest(String filefrom){
    try{
    String hostname = "localhost";
    int port = 80;
    InetAddress addr = InetAddress.getByName(hostname);
    Socket socket = new Socket(addr, port);
    // Send header
    String path ="/php_prgs/var/www/nsboxng/htdocs/tryupdate.php";
    File theFile = new File(filefrom);
    System.out.println ("size: " + (int) theFile.length());
    DataInputStream fis = new DataInputStream(new BufferedInputStream(new FileInputStream(theFile)));
    byte[] theData = new byte[(int) theFile.length( )];
    fis.readFully(theData);
    fis.close();
    DataOutputStream raw = new DataOutputStream(socket.getOutputStream());
    Writer wr = new OutputStreamWriter(raw);
    String command =
    "POST "+path+" HTTP/1.0\r\n"
    + "Content-type: multipart/form-data, boundary=mango\r\n"
    + "Content-length: " + ((int) theFile.length()) + "\r\n"
    + "\r\n"
    + "--mango\r\n"
    + "content-disposition: name=\"MAX_FILE_SIZE\"\r\n"
    + "\r\n"
    + "\r\n--mango\r\n"
    + "content-disposition: attachment; name=\"datafile\"" ;
    String filename="test.doc\"\r\n"
    + "Content-Type: text/doc\r\n"
    + "Content-Transfer-Encoding: binary\r\n"
    + "\r\n";
    wr.write(command);
    wr.flush();
    raw.write(theData);
    raw.flush( );
    wr.write("\r\n--mango--\r\n");
    wr.flush( );
    BufferedReader rd = new BufferedReader(new
    InputStreamReader(socket.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
    System.out.println("out"+line);
    wr.close();
    raw.close();
    socket.close();
    } catch (Exception e) {System.out.println(e.toString());}
    2)
    public void postMethod(String strURL, String filefrom){
    try {
    String fname = filefrom.substring(filefrom.lastIndexOf("/")+1, filefrom.length());
    File input=new File(filefrom);
    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);
    // Request content will be retrieved directly
    // from the input stream
    // Per default, the request content needs to be buffered
    // in order to determine its length.
    // Request body buffering can be avoided when
    // content length is explicitly specified
    post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));
    // Specify content type and encoding
    // If content encoding is not explicitly specified
    // ISO-8859-1 is assumed
    //post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
    post.setRequestHeader("Content-Type","multipart/form-data");
    post.setRequestHeader("Content-Disposition", "form-data; name="+fname);
    // Get HTTP client
    HttpClient httpclient = new HttpClient();
    // Execute request
    try {
    int result=httpclient.executeMethod(post);
    // Display status code
    System.out.println("Response status code: " +result);
    // Display response
    System.out.println("Response body: ");
    // System.out.println(post.getResponseBodyAsString());
    BufferedReader console = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream()));
    String name = null;
    String line = null;
    try {
    while ((line = console.readLine()) != null) {
    System.out.println("output"+line);
    //name = console.readLine();
    catch (IOException e) { name = "<" + e + ">"; }
    // System.out.println("Hello " + name);
    } finally {
    // Release current connection to the connection pool
    // once you are done
    post.releaseConnection();
    catch(IOException e){
    but am getting else condition response from php code
    but if i post with html code it is working fine.
    can anybody help me please where i have to change the code
    please suggest me. am in a big trouble and i have to complete this as soon as possible

    One thread is enough.
    http://forum.java.sun.com/thread.jspa?threadID=5198449
    You could have bumped it instead. Also, you still just posted a junk of unformatted stuff. Furthermore, for HttpClient support ask at an HttpClient mailing list of rorum.

  • How to upload file from Application Server?

    Dear Friends,
    How to upload file from Application Server?
    Plz. with example...
    Regards,
    Dharmesh

    hi,
    check the code for upload from application server.
    tables: kna1.
    types: begin of s_file,
             customer type kna1-kunnr,
             country  type kna1-land1,
             name     type kna1-name1,
             region   type kna1-regio,
           end of s_file.
    *--Internal tables
    data: it_file type s_file occurs 0 with header line.
    *-- Selection screen
    selection-screen: begin of block b1 with frame title text-001.
    parameter: p_file type rlgrap-filename default 'C:/customer.txt'
    obligatory.
    selection-screen: end of block b1.
    *-- At selection screen
    at selection-screen on value-request for p_file.
    perform file_help using p_file.
    *-- Process File
    start-of-selection.
      perform upload_file using p_file.
    *-- write File data to o/p
    end-of-selection.
      perform write_data.
    *&      Form  file_help
    form file_help  using    p_p_file.
      data: l_filepath type ibipparms-path.
      call function 'F4_FILENAME'
    EXPORTING
      PROGRAM_NAME        = SYST-CPROG
      DYNPRO_NUMBER       = SYST-DYNNR
      FIELD_NAME          = ' '
       importing
         file_name           = l_filepath
      p_p_file = l_filepath.
    endform.                    " file_help
    *&      Form  upload_file
    form upload_file  using    p_p_file.
      call function 'WS_UPLOAD'
       exporting
         filename                      = p_p_file
         filetype                      = 'DAT'
    IMPORTING
      FILELENGTH                    =
        tables
          data_tab                      = it_file
       exceptions
         conversion_error              = 1
         file_open_error               = 2
         file_read_error               = 3
         invalid_type                  = 4
         no_batch                      = 5
         unknown_error                 = 6
         invalid_table_width           = 7
         gui_refuse_filetransfer       = 8
         customer_error                = 9
         no_authority                  = 10
         others                        = 11
      if sy-subrc <> 0.
        message i001.
      endif.
    endform.                    " upload_file
    *&      Form  write_data
    form write_data .
      loop at it_file.
        write:/ it_file-customer, it_file-country, it_file-name,
                it_file-region.
      endloop.
      endform.
    regards,
    keerthi.

  • How to upload file from client to server in servlets.

    actually in my application i have to upload file from client m/c to server.
    it is not possible through file i/p stream as fileStreams does not work on network. Please mail me if you have any solution to this.
    Thank's in advance............

    Haii roshan
    Pls go through this thread..
    http://forum.java.sun.com/thread.jspa?forumID=45&threadID=616589
    regards
    Shanu

  • How to transfer file from one client to another client?

    hello,
    i have some questions and hope you all can help me..thanks a lot first..
    Here are the questions:
    i) How can i send a file from one client to another client using RMI?
    ii) Does the client(sender) need to send the file to server, then server save it and then send it to another client(receiver)?
    iii) If using RMI, a client can receive two files from same client(sender) or different client(sender) at a same time? how to do it? when both of the files come in from same port, how to differenciate them?
    iv) For your information, i am doing the File Transfer Server-client application which sender can send any file to other client. Can you give me any ideas? thanks..
    Last, thanks again..

    Your questions reflect some ambiguity in terms.
    "Client" and "server" are commonly used in two different senses:
    1. Technical sense: A client process makes requests, and a server process fulfills the request (provides a service).
    2. IT sense: A client computer (process) makes requests of a server (computer) process, and the server (computer) processes the request.
    In the first case, any computer might be a client, or a server, or both, depending on the processes being executed. In the second case, the computers are assigned some role.
    So: If you wanted to, you could implement client/server processes communicating between two peer computers, using RMI.
    This may not be what you wanted; if you really want to distinguish client and server computers, then the answer is that yes, you will probably put files into intermediate storage on the server computer.
    Finally, you probably do not have to worry about port conflicts if you use RMI; while the initial client server contact is established through a registry operating on a standard port, the actual RMI communications is established using random ports, one for each link.

  • Unable to upload files from local computer to remote server (Was: Dreamweaver)

    I have lost the connection between the remote location and the local location for files on my computer. Where to I correct this issues, since I cannot upload files from local to remote. Host server from server to my computer works fine, Running Dell computerr XP operating system with CS3 Dreamweaver. Need all the help I can get.

    I am now having a "ftp error - cannot make connection to host. Dreamweaver
    encoutered a netwoerk or file system error. I did as you suggested and I
    get to basic site definition, ( which looks o.k.), next screen ( no,I do
    not want to use a server technology) Next screen ( edit local copies on my
    machine ( file location looks o.k.), next screen (connect to remote
    server=ftp) address of web server is correct, ( no folder on server, or ftp
    login or ftp password) do not enable check in or check out
    summary: local
    Site name:midhba
    local root folder:midhba
    remote info:
    access; ftp
    FTP host: midhba.com
    check in.check out diabled
    testing server (set up later)

  • How to upload file from client machine to  database in server machine?

    I am developing a web application. this application is suppose to take file from client machine and store that to database in the server side.
    My jsp form is of multi part type. but I am confused about what to write in servlet.
    Can any one help me ?
    Edited by: chinmaya_mishra on Feb 16, 2009 2:55 AM
    Edited by: chinmaya_mishra on Feb 16, 2009 2:58 AM

    http://www.google.com/search?q=jdbc+blob
    Blob processing varies between databases; see also examples for whatever database you are using, e.g.
    http://www.google.com/search?q=jdbc+blob+oracle
    If you are storing text data instead of binary data, replace "blob" by "clob" in the searches.

  • How to upload file from client machine to  server machine?

    i am developing one web application.I have one html file with browse option. client can browse any type of file. what ever file the client will browse it going to be stored in server machine. for storing the file want to use servlet. my html form is of multipart type.
    can any one send me the servlet code? i am using tomcat 5.5 as web server.

    [http://commons.apache.org/fileupload]
    Start reading 'User Guide' and 'Frequently Asked Questions'.
    Good luck :)

  • How to upload file from one machine (windows) to another (linux)through cre

    How to upload a file from windows platform to linux platform.
    on both platforms sun app server is running.
    from creator is there any methode to open ftp port and upload

    http://www.google.com/search?q=jdbc+blob
    Blob processing varies between databases; see also examples for whatever database you are using, e.g.
    http://www.google.com/search?q=jdbc+blob+oracle
    If you are storing text data instead of binary data, replace "blob" by "clob" in the searches.

  • How to upload file from client to server

    Can someone please help.
    User needs to browse file on his desktop and upload file using browse button. This file should then be uploaded to the server. I am using javascript in the front end and servlet in the back.
    Any help will be highly appreciated.
    Thanks,
    Indrasish

    Jakarta Commons FileUpload is the standard way of doing the file uploading these days. You can find source, binaries and documentation at the Jakarta Site http://jakarta.apache.org/ . The Commons has a number of subprojects, so start with the Commons libraries, then find FileUpload.
    Brian

  • Uploading Multiple Files from web client to web server

    Am using a Digitally signed applet to pickup files from a specific directory and only to pickup those of a specific type. Applet is called by a HTML converted page and uses the JAVA 1.3.1 plug-in. Client side is ok, but the server side does not work - cannot see how to drop the files down onto the web server.
    code
    URL url = null ;
    FileInputStream filReader = null ;
    DataOutputStream dosOutfile = null ;
    HttpURLConnection httpUrlConn = null ;
    int bytes = 0 ;
    //read local file on client's hd with signed applet
    try
    filReader = new FileInputStream( new File( fromFile ) );
    catch ( java.io.FileNotFoundException eNotFound )
    DisplayStatus ( fromFile + " Not found");
    eNotFound.printStackTrace();
    // start setup to server-side copy of in file
    try
    url = new URL ( toFile ) ;
    catch ( java.net.MalformedURLException eMalFormedUrl )
    DisplayStatus ( url + " url mal formed");
    eMalFormedUrl.printStackTrace();
    // create a HttpUrl connection for POSTING
    try
    httpUrlConn = (HttpURLConnection) url.openConnection(); // do not remove this casting, as needed
    catch ( java.io.IOException eIoException )
    DisplayStatus ( url + " IO not possible");
    eIoException.printStackTrace();
    // set preferences
    httpUrlConn.setDoInput(true); // default value, but best make sure
    httpUrlConn.setDoOutput(true); // default value, but best make sure
    httpUrlConn.setUseCaches(false); // enable write straight through
    try
    httpUrlConn.setRequestMethod("POST") ;
    // httpUrlConn.setRequestMethod("PUT") ;
    } catch ( java.net.ProtocolException eProtEx )
    DisplayStatus ( "Protocol Exception on setting up POST") ;
    eProtEx.printStackTrace();
    httpUrlConn.setRequestProperty("Content-Type", "multipart/form-data");
    // permissions?
    try
    java.security.Permission permission = httpUrlConn.getPermission() ;
    if ( iDebug == true )
    DisplayStatus ("Permission = " + permission.toString() ) ;
    DisplayStatus ( "Actions = " + permission.getActions() ) ;
    DisplayStatus ( "Name = " + permission.getName() ) ;
    catch ( java.io.IOException eUrlIOConnException )
    DisplayStatus ( "httpUrl " + httpUrlConn + " IO not possible");
    DisplayStatus ( eUrlIOConnException.toString() ) ;
    eUrlIOConnException.printStackTrace();
    // connect
    try
    this.VerifyHttpResponseCode ( httpUrlConn.getResponseCode() ) ;
    DisplayStatus ("About to connect") ;
    httpUrlConn.connect() ;
    DisplayStatus ("Connected") ;
    if ( iDebug == true )
    DisplayStatus ("Connected Content Encoding = " + httpUrlConn.getContentEncoding() ) ;
    DisplayStatus ("Connected Content Length = " + httpUrlConn.getContentLength() ) ;
    DisplayStatus ("Connected Content Type = " + httpUrlConn.getContentType() ) ;
    DisplayStatus ("Connected default allow user interaction = " + httpUrlConn.getDefaultAllowUserInteraction() ) ;
    DisplayStatus ("Connected File Map = " + httpUrlConn.getFileNameMap() ) ;
    DisplayStatus ("Connected request method = " + httpUrlConn.getRequestMethod() ) ;
    DisplayStatus ("Connected response code = " + httpUrlConn.getResponseCode() ) ;
    DisplayStatus ("Connected response message = " + httpUrlConn.getResponseMessage() ) ;
    DisplayStatus ("Connected = " + httpUrlConn.getURL() ) ;
    } // end of debug print out status
    catch ( java.net.ConnectException eConnEx )
    this.DisplayStatus ( "Connection error - no server listening or incorrect port " ) ;
    this.DisplayStatus ( "Connection error - http = " + httpUrlConn) ;
    eConnEx.printStackTrace();
    catch ( java.io.IOException eUrlConnException )
    DisplayStatus ( "url " + url + " connection not possible");
    DisplayStatus ( eUrlConnException.toString() ) ;
    eUrlConnException.printStackTrace();
    // create file on server
    try
    dosOutfile = new DataOutputStream ( new BufferedOutputStream( httpUrlConn.getOutputStream () ) ) ;
    catch ( java.io.IOException eNewFileIO )
    DisplayStatus ("Unable to create file on server / buffer output stream " + toFile ) ;
    // copy files char by char for the moment, till testing complete
    try
    bytes = filReader.read();
    while(bytes != -1)
    dosOutfile.writeByte(bytes);
    bytes = filReader.read();
    // close both files
    dosOutfile.flush ();
    dosOutfile.close ();
    filReader.close();
    catch (java.io.IOException eCpyIo )
    DisplayStatus ("Error copying files") ;
    connection of the HttpURLConnection
    gives 'Fobbiden' response for 'PUT'
    and
    'method not allowed' for 'POST'
    trying to create the file on the server than causes IOException at the create DataStream line
    What am I doing wrong?
    Is this philosphy correct?
    Should the HttpURLConnection be to the target folder
    and then create the file in it?

    hello,
    first here is my interpretation of your prob.
    You have a client.From this client you are trying to upload files onto a server.
    Finding the files and reading them on the client side is not a prob. The prob is storing them on the server side.
    right?
    If the above stated prob is right, here is a solution.
    1. You have to first inform the server that you are sending the file. Unless you do so the server will not understand when you have started sending the file.
    So, initially, the applet which you have written need to communicate with a servlet on the server side.
    This can be done using reqs.. .get or post.In the req itself you can even send the name of the folder wherein you want to store the file you are going to transfer later on.
    Next, after receiving the folder name, the servlet can now understand that next file data is going to be received.
    The applet now sends the file which is received by the servlet and stored appropriately.
    You need to explicitly write a servlet to receive a data into the file and then store the file into appropriate folder.
    for any further probs email me at [email protected]

  • How to upload file from desktop or C drive and send as attachments

    Hello Experts,
    Please tell me
    How to upload jpg or gif or drawing files from desktop or any drive and store into R/3 by the same time I have to send mail as a attachment.
    I heard that FM
    SO_NEW_DOCUMENT_ATT_SEND_API1  is only to send as a  attachment what ever the data is present in the internal table only.
    please help me on that.

    I m using this code its having attachment but I m not able to open the file. Please help me
    I m using gui_upload to upload the file
    PROGRAM  ZTEST
           no standard page heading line-size 255.
    DATA: xfile TYPE string.
    data :     t_IW51 LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    DATA: OBJPACK   LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
    DATA: OBJHEAD   LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
    DATA: OBJBIN    LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    DATA: OBJTXT    LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    DATA: RECLIST   LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
    DATA: DOC_CHNG  LIKE SODOCCHGI1.
    DATA: TAB_LINES LIKE SY-TABIX.
    data :  email type table of BAPIADSMTP.
    PARAMETERS : file LIKE rlgrap-filename OBLIGATORY.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR file.
      CLEAR file.
      CALL FUNCTION 'F4_FILENAME'
        IMPORTING
          file_name = file.
      xfile = file.
    START-OF-SELECTION.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename            = xfile
          filetype            = 'ASC'
          has_field_separator = 'X'
        TABLES
          data_tab            = t_IW51.
    Creation of the document to be sent
    File Name
      DOC_CHNG-OBJ_NAME = 'SENDFILE'.
    Mail Subject
      DOC_CHNG-OBJ_DESCR = 'Send External Mail'.
    Mail Contents
      OBJTXT = 'Minimum bid : $250000'.
      APPEND OBJTXT.
      OBJTXT = 'A representation of the pictures up for auction'.
      APPEND OBJTXT.
      OBJTXT = 'was included as attachment.'.
      APPEND OBJTXT.
      DESCRIBE TABLE OBJTXT LINES TAB_LINES.
      READ TABLE OBJTXT INDEX TAB_LINES.
      DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
    Creation of the entry for the compressed document
      CLEAR OBJPACK-TRANSF_BIN.
      OBJPACK-HEAD_START = 1.
      OBJPACK-HEAD_NUM = 0.
      OBJPACK-BODY_START = 1.
      OBJPACK-BODY_NUM = TAB_LINES.
      OBJPACK-DOC_TYPE = 'RAW'.
      APPEND OBJPACK.
    Creation of the document attachment
    (Assume that the data in OBJBIN is in BMP format)
    *OBJBIN = ' \O/ '. APPEND OBJBIN.
    *OBJBIN = ' | '. APPEND OBJBIN.
    *OBJBIN = ' / \ '. APPEND OBJBIN.
      OBJBIN[] = t_IW51[].
      DESCRIBE TABLE OBJBIN LINES TAB_LINES.
      OBJHEAD = 'PICTURE.PDF'.
      APPEND OBJHEAD.
      OBJBIN[] = t_IW51[].
    Creation of the entry for the compressed attachment
      OBJPACK-TRANSF_BIN = 'X'.
      OBJPACK-HEAD_START = 1.
      OBJPACK-HEAD_NUM = 1.
      OBJPACK-BODY_START = 1.
      OBJPACK-BODY_NUM = TAB_LINES.
      OBJPACK-DOC_TYPE = 'PDF'.
      OBJPACK-OBJ_NAME = 'PICTURE'.
      OBJPACK-OBJ_DESCR = 'Representation of object 138'.
      OBJPACK-DOC_SIZE = TAB_LINES * 255.
      APPEND OBJPACK.
    Completing the recipient list
      RECLIST-RECEIVER = 'email_id have to enter here'.
      RECLIST-REC_TYPE = 'U'.
      APPEND RECLIST.
      RECLIST-RECEIVER = 'ENTEG01'.
      RECLIST-REC_TYPE = 'P'.
      APPEND RECLIST.
    Sending the document
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
         DOCUMENT_DATA = DOC_CHNG
         PUT_IN_OUTBOX = 'X'
         commit_work = 'X'
      TABLES
         PACKING_LIST = OBJPACK
         OBJECT_HEADER = OBJHEAD
         CONTENTS_BIN = OBJBIN
         CONTENTS_TXT = OBJTXT
         RECEIVERS = RECLIST
    *EXCEPTIONS
      TOO_MANY_RECEIVERS = 1
      DOCUMENT_NOT_SENT = 2
      OPERATION_NO_AUTHORIZATION = 4
    *OTHERS = 99.
      CASE SY-SUBRC.
        WHEN 0.
          WRITE: / 'Result of the send process:'.
          LOOP AT RECLIST.
            WRITE: / RECLIST-RECEIVER(48), ':'.
            IF RECLIST-RETRN_CODE = 0.
              WRITE 'The document was sent'.
            ELSE.
              WRITE 'The document could not be sent'.
            ENDIF.
          ENDLOOP.
        WHEN 1.
          WRITE: / 'No authorization for sending to the specified number',
                   'of recipients'.
        WHEN 2.
          WRITE: / 'Document could not be sent to any recipient'.
        WHEN 4.
          WRITE: / 'No send authorization'.
        WHEN OTHERS.
          WRITE: / 'Error occurred while sending'.
      ENDCASE.

  • How to upload files from a form using pl/sql ?

    Hi
    Is it possible to upload the physical files outside the database (under UNIX server)using pl/sql? I already know how to store the files inside the database(wwwdoc_documents$) but I didn't find any documentation about storing the physical files outside the database.
    I have in my form the following component:
    <input type="file" name="upload">
    and I want to let the user browse for the file on his/her disc that he want to use. What I want to do next is to save a copy of that file on our file-server, and then use it in my application. How do I do that in pl/sql?
    Any help will be appreciated.
    Sebas.

    Thanks for the suggestion. I like this approach as Java is more familiar to me than other languages.
    Our DBA is out of touch today, so I could not grant the javauserpriv to my database user. I tried to run the script anyway in the chance that my user had the privs, and it seemed to have hung. I am now combing Oracle's site for more documentation so I can write some tests to see if I can get a basic Java object working. Under what heading would I find this?
    ajt

  • Problem uploading file from mobile device to tomcat server

    Hi guys, here's how it goes.
    I'm designing a site using JSP for wireless devices like PDAs, Smartphones etc, basically any mobile device that has browser capabilities. There's a page where the user is allowed to upload a file from the mobile device, which works perfectly fine when I access the site using a PC. But when I try to upload a file from a mobile device, ( I tried using a Nokia 6680 ) , there wasn't any error but the file just wasn't stored in my server.
    Here's how the upload form looks like :
    <FORM name="filesForm" action="ProcessFileUpload.jsp" method="post" enctype="multipart/form-data">
            <font size="1" face="arial">File :</font><br>
    <input type="file" name="file1" size="10" style="font-size: 9px;"/><br><br>
            <input type="submit" name="Submit" value="Upload Files" style="font-size: 9px;"/>
        </FORM>Here's the gist of ProcessFileUpload.jsp:
    <%
         System.out.println("");
            System.out.println("Content Type ="+request.getContentType());
            DiskFileUpload fu = new DiskFileUpload();
            // If file size exceeds, a FileUploadException will be thrown
            fu.setSizeMax(1000000);
            List fileItems = fu.parseRequest(request);
            Iterator itr = fileItems.iterator();
            while(itr.hasNext()) {
              FileItem fi = (FileItem)itr.next();
              //Check if not form field so as to only handle the file inputs
              //else condition handles the submit button input
              if(!fi.isFormField()) {
                System.out.println("NAME: "+fi.getName());
                System.out.println("SIZE: "+fi.getSize());
                System.out.println(fi.getOutputStream().toString());
               // File fNew= new File(application.getRealPath("/"), fi.getName());
             File tempFileRef  = new File(fi.getName());
             File fNew = new File(filepath.toString(),tempFileRef.getName());
         String MM_Overall_DRIVER = "org.gjt.mm.mysql.Driver";
         String MM_Overall_USERNAME = "****";
         String MM_Overall_PASSWORD = "*********";
         String MM_Overall_STRING = "jdbc:mysql://localhost:3306/";
         Driver DriverRecordset1 = (Driver)Class.forName(MM_Overall_DRIVER).newInstance();
         Connection ConnRecordset1 = DriverManager.getConnection(MM_Overall_STRING,MM_Overall_USERNAME,MM_Overall_PASSWORD);
         PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("use " + domain);
         ResultSet Recordset1 = StatementRecordset1.executeQuery();
         filepath.append("/").append(tempFileRef.getName());
         StringBuffer fp = new StringBuffer("insert into ");
         fp.append(domain).append(".filepaths (path) values ('").append(filepath).append("')");
         PreparedStatement ps = ConnRecordset1.prepareStatement(fp.toString());
         ps.executeUpdate();
                System.out.println(fNew.getAbsolutePath());
                fi.write(fNew);
              else {
                System.out.println("Field ="+fi.getFieldName());
            }Basically I store the file uploaded in the tomcat server and the path of the file is saved in a table in MySQL.
    When I upload a file using a PC, the tomcat console displays the content type file name yada yada yada. However, when I upload a file from the Nokia 6680, I get just the content type then things just stop there and nothing else happens. No file name no file size whatsoever. The path of the file is not inserted into MySQL and the file is not stored in the server.
    Can anyone please enlighten me on this issue and hopefully gimme a solution to this problem? Your help will be greatly appreciated.

    -bump-
    HELPP!?!?!?!?!

  • Help: question on send XML file from java client to java server

    Hi, I am now to Java, and now I am going to set up a simple network in the lab.
    I have created a random array of data and transferred to XML file on my client. Now, I would like to send it to the server. I am wondering how I can put the XML file into my client, and do I need any parser to let the server show what random date it has received?
    Anybody can give me any idea or some basic code? Thank you.
    Now, I am referring the KnockKnock example in Java online tutorial. But, not clear how to deal with the XML File.
    Fengyuan

    There are several ways you can achieve this: one could be that you transfer data over HTTP, using Servlets for instance. Have a Servlet listening on the Server with content type 'text/xml', POST the XML data to the server and have the Servlet to receive the data and re-compose the XML file. This can be achieved with different libraries:
    1) JAXB --> this is good because is the JDK standard, also for web services
    2) Castor (http://www.castor.org/)

Maybe you are looking for