How to upload a XML file to Servlet

Hi,
I am new to Java, I have to upload an XML file to java/j2ee server. The web server running on the server is "Tomcat 4.1". My new requirement is I have to upload an "Input.XML" file, can you please tell me how to upload an XML file. If any samples appriciated very soon.
Thanks & Regards,

Hi!
On the client side, the client's browser must support form-based upload. Most modern browsers do, but there's no guarantee. For example,
<FORM ENCTYPE='multipart/form-data'
method='POST' action='/myservlet'>
<INPUT TYPE='file' NAME='mptest'>
<INPUT TYPE='submit' VALUE='upload'>
</FORM>
The input type &quot;file&quot; brings up a button for a file select box on the browser together with a text field that takes the file name once selected. The servlet can use the GET method parameters to decide what to do with the upload while the POST body of the request contains the file data to parse.
When the user clicks the "Upload" button, the client browser locates the local file and sends it using HTTP POST, encoded using the MIME-type multipart/form-data. When it reaches your servlet, your servlet must process the POST data in order to extract the encoded file. You can learn all about this format in RFC 1867.
Unfortunately, there is no method in the Servlet API to do this. Fortunately, there are a number of libraries available that do. Some of these assume that you will be writing the file to disk; others return the data as an InputStream.
You can see more things about Servlet on this website [http://pedrofao.blogspot.com|http://pedrofao.blogspot.com].

Similar Messages

  • How to upload an XML file into another system

    Hi friends,
    I have a requirement where I need to upload an  XML file into one system
    which has been downloaded  using  another  system.
    I have tried using the method ' cl_gui_frontend_services=>gui_upload'
    to upload the file but it is going for dump.
    I have used the  method ' w_xml->import_from_file' also,
    but it is also going for dump ,because  both methods are using the same FM
    ' GUI_UPLOAD'.
    Can any one suggest on this.
    Regards,
    Bhargavi.D

    "Here is the  Explaination for uploading the XML   Format file to sap   " through ABAP Program ....
    1. Basically you simply have to convert the XML file into the proper IDoc format. There are many ways to achieve this. One solution would be to convert it externally to SAP, e.g. via VB Script or with an XSLT transformation. Or you use the built in SAP functions for importing an IDoc from an XML stream.
    2. Uploading a file is either done via GUI_UPLOAD or via the usual way of reading a file from the application server (Open dataset. Read dataset) But what do you mean by "send to external system"? Do you want to convert an IDoc into XML? Then you simply define an XML port with WE21 to send the IDoc out.
    Here is an example of code that loads an XML from file and posts it as an IDoc. Please keep in mind that the XML has to be in its canonical format as described in the interface repository: ifr.sap.com (choose the template of the desired IDoc from there as an example).
    data: data_tab type table of char1024.
    data: XML_STREAM type string.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = 'D:test.xml'
    *   FILETYPE                      = 'ASC'
    *   HAS_FIELD_SEPARATOR           = ' '
    *   HEADER_LENGTH                 = 0
    *   READ_BY_LINE                  = 'X'
    *   DAT_MODE                      = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    *   CHECK_BOM                     = ' '
    * IMPORTING
    *   FILELENGTH                    =
    *   HEADER                        =
      TABLES
        DATA_TAB                      = DATA_TAB
    EXCEPTIONS
       FILE_OPEN_ERROR               = 1
       FILE_READ_ERROR               = 2
       NO_BATCH                      = 3
       GUI_REFUSE_FILETRANSFER       = 4
       INVALID_TYPE                  = 5
       NO_AUTHORITY                  = 6
       UNKNOWN_ERROR                 = 7
       BAD_DATA_FORMAT               = 8
       HEADER_NOT_ALLOWED            = 9
       SEPARATOR_NOT_ALLOWED         = 10
       HEADER_TOO_LONG               = 11
       UNKNOWN_DP_ERROR              = 12
       ACCESS_DENIED                 = 13
       DP_OUT_OF_MEMORY              = 14
       DISK_FULL                     = 15
       DP_TIMEOUT                    = 16
       OTHERS                        = 17
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'CONVERT_TABLE_TO_STRING'
      EXPORTING
        I_TABLINE_LENGTH       = '1024'
      IMPORTING
        E_STRING               = XML_STREAM
      TABLES
        IT_TABLE               = DATA_TAB[].
    write: / xml_stream color col_total.
    data: CONTENT_LENGTH type string.
    data: CONTENT_TYPE type string.
    data: REMOTE_ADDR type string.
    CALL FUNCTION 'IDOC_INBOUND_XML_VIA_HTTP'
      EXPORTING
        XML_STREAM                      = XML_STREAM
        CONTENT_LENGTH                  = content_type
        CONTENT_TYPE                    = content_type
        REMOTE_ADDR                     = remote_addr
    EXCEPTIONS
       NO_IDOCS_SAVED                  = 1
       TAG_ERROR                       = 2
       NO_DATA_RECEIVED                = 3
       NO_IDOCS_RECEIVED               = 4
       SEGMENT_ERROR                   = 5
       IDOC_WAS_SEND_SECOND_TIME       = 6
       OTHERS                          = 7
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    write: / sy-subrc color COL_NEGATIVE.
    ENDIF.
    reward  points if it is usefull.......
    Girish

  • How to parse the xml file using servlet

    My scenario is like this:
    <b>FILE-->XI-->J2EE Application</b>
    XI sends the xml file to j2ee application. My servlet receives the file in HTTPRequest string. 
    How to parse that file using servlets.I should get the xml file as it is and should be displayed in the browser.
    Can anyone please help me with code, its urgent.
    Please help me!

    Download this java code
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java
    in your servlet code you can write
    public void doPost(req,resp){
    DefaultHandler handler = new Echo02();
    handler.parse(req.getInputStream());
    Offcourse you will need to modify the code of Echo02 class a bit to suit your requirement which would finally retrun you a string and you can then write it using
    respose.getWriter().write(responseString);

  • How to upload a XML File in database

    i use Blob type to set domain the Xml file. But i don't know use what class to define it.i only know use OrdHttpUploadFile to define a image. What class do i use to define a Xml file.

    during my tries to adapt this code to my needs, following error occured during compilation of the procedure:
    PLS-00201: identifier 'IMAGES.MIME_TYPE' must be declared
    here is my procedure:
    CREATE OR REPLACE PROCEDURE load_file( file_name VARCHAR2 )
    AS file_lob BFILE;
    binary_lob BLOB;
    mime_type images.mime_type%TYPE;
    extension_pos NUMBER;
    BEGIN
    --Use the extension of the file name to determing the MIME-type 
    --The MIME-type for a .pdf file will be application/pdf
    extension_pos := INSTR( file_name, '.' );
    mime_type := 'application/' || SUBSTR( file_name,extension_pos + 1,LENGTH( file_name ) );
    -- Insert a new row into the images table. Get the LOB locator
    -- for the newly inserted row
    -- we will be using that to insert
    -- the content from the file.
    INSERT INTO TESTBLOB( blobid, filename, mime_type, content )
    VALUES( 1, file_name, mime_type, EMPTY_BLOB() )
    RETURNING content INTO binary_lob;
    -- Open up the file in the IMAGES directory named file_name,
    -- load that file into the newly created LOB locator, and
    -- close the file
    file_lob := BFILENAME( 'TESTDIRECTORY', file_name );
    dbms_lob.fileOpen ( file_lob, dbms_lob.file_readOnly );
    dbms_lob.loadFromFile( binary_lob,file_lob,dbms_lob.getLength( file_lob ) );
    dbms_lob.fileClose ( file_lob );
    END;
    how do I have to adjust the declaration of the mime_type variable respectively what does images.mime_type%TYPE mean?
    katharina

  • Please Help ! How would i Read xml file through servlet

    My requirement is that i have to make a stock exchange streamer.
    i am making an applet to show real time data to client. i had succeded in applet-servlet communication, but i m getting problem in
    parsing the xml files inside a servlet and throw it to applet again.

    I would suggest that you find out what the problem is, then. Once you find that out you will be far ahead of anybody else reading this post, because they have absolutely no idea what your problem is.

  • Upload an XML file into the Internal table

    Hi Guys,
    I want to know, how to upload an xml file into the Internal table through ABAP programming

    you just wanted to load the xml file into internal table (as a table of binary strings)or load the xml data mapped to itab row columns
    for the first one you can simply use gui_upload
    and for the second one you need to load the xml file using gui_upload and use XLST program to transform into an itab
    Regards
    Raja

  • How do I upload an XML file to salesforce using BULK API?

    Hi There,
    Please let me know how do we upload an XML file to salesforce using Bulk API?
    Thanks,
    ET

    Hi,
    I think that this is a more SalesForce.com question and think you will have more chance looking at SOAP API Developer's Guide for salesforce. Sending a SOAP request from the API Server is very straight forward and there are several tutorials and well documented about this.
    Cheers,
    Stefan

  • Keeping contact with controlling applet while u/l XML file via servlet

    Hello everybody,
    if I am thinking too complicated, please send me other suggestions. Here's the situation:
    I already have a working applet for a metadata application, that is sending the contents of the client's textfields to a remote database via servlet communication. Now I want to implement the following:
    -The users have some attribute data in form of an XML file
    -I want them to upload this file to the server (I already have that functionality using the fileUpload libraries of Apache Commons) by calling the servlet from a pop-up html page (is there any other possibility to do the communication, i.e. getting files from the file system?)
    -the XML file should be parsed on the server and the content should be sent back to the calling applet for previewing reasons.
    -when the user gives his/her O.K. the data should be transferred to the database.
    Now there are some obstacles to overcome: When I upload the XML file to the server, I loose "contact" with the applet, i.e. the file is not connected with the applet code in any way. This is not a problem, when there is only one user at the time, but with many users loading up their data at the same time, things could get tricky.
    What I thought was to copy the XML file to a temp directory with a unique name, the name of which would be transferred back to the applet by another servlet that is called when the (upload)pop-up window closes. The name of the temp directory could be the ID of the applet thread (is there such an ID, if yes, how can it be retrieved?)
    Any suggestions (or just shaking heads concerning my complicated construction ;-) )
    Cheers and many thanks in advance
    Jan

    You may be able to read a file from the file system with the applet, but it may require you to sign the applet. If you can, then use an HttpURLConnection to the servlet and send the file that way.
    On the server side, you could create a session object (wether you actually need a session or not), and use the session's id as the key id for the directory name for the uploaded file. Session IDs are unique per client, and if the client handles cookies, then the same session will be used from one request to the next.
      session = request.getSession();
      String sessionID = session.getId();The response from the servlet would be a link to the server-side file. If you are using the Applet to send the request, you could get the response and automatically view the new file. Otherwise, you could send a page to the popup window saying: "Click This Link To See Your File" type of thing.

  • How to transfer an xml file to NW Portal Knowledge Management from XI?

    Hi all,
    Anybody knows how to transfer an xml file to NW Portal Knowledge Management from XI?
    What kind of adapter type I have to choose? And which procedures I have to do in KM Portal? Create a folder, what kind of folder and permissions?
    Suggestions and ideas are appreciated.
    Thanks in advance,
    Ricardo.

    Hi
    Can anyone tell me how XI sends messages to applications like J2EE. In REceiver comm channel, I think we specify about the target system like J2EE appl.
    Aadapter Type: HTTP
                   Receiver
    Transport Protocol:  HTTP1.0
    Message Protocol:    XI payload in HTTP body
    Adapter Engine:      Integration Server
    Addressing Type:     URL address
    Target host:         localhost
    Service Number:      7001(Port number of Weblogic appl server--where my J2EE appl is deployed).
    Path     :  /Invoke/DisplayRes/
    Authentication Type:Use Logon Data for SAP System
    Content Type: text/xml
    Username:   xiappluser
    password:   xx
    XML code:   UTF-8
    I suppose XI sends msgs to http://localhost:7001/Invoke/DisplayRes/........
    in this example if am correct?
    Then I have given all tyhe necessary setting but my servlet is not able to display XML msg in browser?
    This is my servlet code:
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         PrintWriter out = response.getWriter();
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
            response.setContentType("text/xml");
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);
             out.println("hi");            
                out.println(sBuf.toString());
             brin.close();
             out.flush();
    What went wrong?
    Help me, all helpful answers are highly rewarded.
    Thanks

  • How to upload MAM.war file to WebConsole

    Does anyone know how to upload MAM.war file to webconsole?  We just finish installed the middleware and client MI but don't know how to install MAM application.  I know the application have to deploy from the Webconsole but where can I find application?  Any helps would be appricated.

    Hi Dai Ly,
    Look at all these links for finding your solution...
    <b>A Similar topic dicussed here...</b>
    How to deploy MAM 2.5 into MI Server
    <b>MAM Enhancement Guides.....( All in One )</b>
    https://websmp105.sap-ag.de/~form/sapnet?_SHORTKEY=01200252310000047008&
    <b>Export a .war file</b>
    Export MAM into .war
    <b>
    How to name MAM application in WebConsole</b>
    How to name MAM application in WebConsole
    <b>Look at this link about MAM Installation.</b>
    MAM Installation
    <b>Look at this thread...</b>
    MAM help
    <b>
    FAQ's on MAM.</b>
    http://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/mi/mobile applications/mobile application faq/mam client faq.faq
    <b>MAM Documents...</b>
    MAM document needed
    Hope it helps.
    Regards,
    Maheswaran.B

  • How to upload a image file ....

    Hi
    Need some tips ....
    How to upload a image file?
    How to limit the size of the file?
    if the image is big in size means how to make it small ?
    Is it possible of compressing the file before storing ..?
    thanks in advance
    kumar

    You may find the following articles useful for the JSP/Servlet part:
    Uploading files: http://balusc.blogspot.com/2007/11/multipartfilter.html
    Downloading files: http://balusc.blogspot.com/2007/07/fileservlet.html

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • How to upload a text file from a shared folder and provide an o/p

    how to upload a text file from a shared folder and provide an o/p  containing the details in each order in the text file

    Hi,
    Use <b>GUI_UPLOAD</b> to upload a text file from a shared folder.
    Use <b>GUI_DOWNLOAD</b> to download data in a file on the presentation server or use <b>OPEN DATASET, TRANSFER</b> and <b>CLOSE DATASET</b> statements to download data to the application server.
    Now, I hope the code for data fetching, if required, is already present in the report.
    Reward points if the answer is helpful.
    Regards,
    Mukul

  • How to Merge multiple XML  files in one file ( Env: XML Publisher 5.6.2)

    All,
    I have recently started working on XML publisher and have developed 3 reports in last 2 days using XML Publisher and integrating them with Concurrent programs.
    This is a great tool.
    I have got another requirement, where i need to use xml file generated by multiple run of same report with various parameters and then merge all xml file to a single report. Developing the whole custom process will take very long time and sure will have bugs in it. Instead i was thinking to use xml file generated by Oracle report itself.
    Report "US Gross to net summary" generates xml output in standard output directory and then show output in PDF file. I have 7 such file generated for each payroll. I want to merge output of xml into a single xml so that i can create single report having data from all 7 xml files showing me All payroll output in a single report.
    Can someone please guide me , how can i read xml file data from the output directory of a seeded concurrent program and how to manipulate data in it.
    Thanks
    Ankur

    Hi Tim,
    Thanks for replying. I have looked for "PDFBookBinder class" in xml publisher user guide for ver 5.6.2. I didn't get any reference of this text. Can you please guide me to a tutorial/link where i can get more information about this class.
    Also, i originally thought of similar to your second logic, as my design basis. Oracle process generates the xml file in output directory which i can get. What i didn't get is how do i "pick them up and merge" using publisher. Also, is there way to do this merging process using pl/sql ? Can you please give little more information on your second approach.
    My original plan of action is that i will create a report set in which i will call oracle seeded report for all 7 payrolls in a sequential manner. Then using the child requests of the report set i will get to 7 xml files generated by seeded oracle process. Then the piece i am not sure of , i will use those 7 files to generate a single xml file having payroll name as tree top for each output. Once single xml is ready, i can easily design a template and register the process to generate output as Excel.This process will not require me to actually change any data or do any calculation. It will only reformatting the feilds we see and abiity to see all 7 payroll at one time rather then entering these numbers manually into an excel to do analysis.
    Please provide your feedback, if you think above plan is not feasible or need corrections.
    Best Regards,
    Ankur

  • Uploading an XML file from SAP into third party URL

    Hi,
    I need to Upload an XML file from sap into Third party URL. Can any body tell me the possible ways in SAP to achieve this task. Also explain me the proceedure.
    Thanks in advance.
    -Namdev

    Sorry. If they only said HTTP/HTTPS and didn't say explicitly web service, it means they don't want it.
    One thing I'm not sure is, do you have an URL at the third-party system that you need to contact, or should you provide one at your SAP system that they will contact?
    If it is the first one, to send an HTTP request to a given URL using ABAP, you'll find an example here: [SAP Library: Example Program: Executing an HTTP Request|http://help.sap.com/saphelp_nw70/helpdata/en/1f/93163f9959a808e10000000a114084/frameset.htm]
    Sandra

Maybe you are looking for

  • Getting COM Component error while opening SSIS Script task.

    Hi All, While click on EDIT SCRIPT Button in script task it's not opening the script editing window. Getting below error message: "Error HRESULT E_FAIL has been returned from a call to a COM component. (EnvDTE)" We have added ADODB reference in scrip

  • J2sdk1.4.1 instalation in Solaris 2.6

    Hi, I've installed the "j2sdk-1_4_1-rc-solaris-i586.sh" (Solaris j2sdk1.4.1) and "J2SE_Solaris_2[3].6_x86_Recommended.tar.Z" (patch for solaris 2.6). And make the j2sdk1.4.1 de default java. When running java, the following message ocurrs: 18:03 eid@

  • MP4 videos for Asha 206

    my asha 206 does not play mp4 videos and does not support viber I edited the title of the post and provided an appropriate one. 

  • IMovie not communicating with camcorder

    i have a panasonic pv-gs14 and i got imovie 6. I used a firewire cable and made sure it was securely in. I tried turning the camera on and off (same in imovie), etc., etc. HELP! PowerBook G4, 12-inch   Mac OS X (10.4.8)   Puhcased in 2004

  • How to use the airport express to extend the range of an existing airport extreme wireless network?

    The instruction manual says nothing on the topic, so maybe it is not possible. The only reason I think it is possible is that two different Apple reps told my girlfriend it was possible. Now we have one, and no clue how to proceed. We have an Airport