Reading form file data in servlet

Does anyone have any familiarity with reading data posted by a form such as the following in a servlet:
<form method="post" action="load_user_file">
Label: <input type="text" name="label" size="20"><br>
Data to be sent: <input type="file" enctype="multipart/form-data" size="50"><br>
<input type="submit" name="Submit">
</form>
I would really prefer to get the label data in the "usual way," through the request parameters, but failing that, some way to parse the information "automatically" would be good.
Thanks in advance for any help!
- Jerry Oberle

you want to upload a file....
the best resource will be to look at MultipartRequest class which can be found at
www.servlets.com
anurag
[email protected]

Similar Messages

  • Is it possible to read PDF file data by using Webdynpro Abap?

    Hi,
    I have an requirement, where customer will upload an PDF file on an application and i need to read some data from pdf file.
    The pdf file contains only text data in tabular format.
    In past i developed an application for uploading data from Excelshet by using WDA . But just wondering, whether it is possible to upload the data from Pdf file also. ( Also if not possible then what could be other way to read PDF file data in abap)
    Regards
    PG

    NB - the "data" that is returned by these classes is the data as defined in an adobe form - it doesn't return the content of non-form PDF documents.
    The PDF must be an interactive form ( although that doesn't restrict you to using the SAP process for creating the form is my understanding - but I could be wrong. )
    Edit - I was wrong! ONLY PDF documents that have been created by the ADS can have data extracted using these classes. So unless you are using Adobe interactive forms - then you will get no value from this functionality - and if you're using AIF then you're probably just use the standard UI element
    Edited by: Chris Paine on Oct 26, 2010 6:04 PM

  • How to synchronize if one servlet read a file and anothe servlet update the

    How to synchronize if one servlet read a file and anothe servlet update the file at a time?

    Create a class that holds the reference to the file and do the whole file manipulation just in that class. than synchronize the read and write methodes. A reference to this file handler class can be stored to the servlet context in one servlet and read out from the servlet context in the other servlet.

  • Getting .txt file data from servlet

    I am having problem finding the file I use "reguli.txt" to define page rules of a website.
    I use this file in a servlet.The file I copied it in the project folder,and also in /web/web-inf folder.
    The problem is I cant find the file without using all the path in this line: File filename = new File("reguli.txt");
          String filepath = filename.getAbsolutePath();
                FileInputStream file = new FileInputStream(filepath);
                InputStreamReader isr = new InputStreamReader(file);
                BufferedReader br = new BufferedReader(isr); I tried also:
    ServletContext context = getServletContext();
                InputStream contextPath = context.getResourceAsStream("/reguli.txt");
                InputStreamReader isr = new InputStreamReader(contextPath);
                BufferedReader br = new BufferedReader(isr);And I still get the same error:
    SEVERE: StandardWrapperValve[Servleet]: PWC1406: Servlet.service() for servlet Servleet threw exception
    java.io.FileNotFoundException: D:\Users\Stefan\GlassFish_v3_Prelude\glassfish\reguli.txt (The system cannot find the file specified)
    What am I doing wrong?

    Put the file directly under your webapps root context and access using following code
            String filename = "/InputFile.txt";
            ServletContext context = getServletContext();
            InputStream is = context.getResourceAsStream(filename); regards,
    nirvan.

  • Read a file resource in servlet

    Hello,
    I try to read a file ressource in a Servlet with following statements:
    ServletContext ServCont = this.getServletContext();
    String strConfFile = ServCont.getRealPath("/xml/config.xml");
    With Tomcat5.5 it works, but with Bea 9.1 I get null.
    I tried also read from a system ressource:
    String strConfFile1 = System.getProperty("PTSHISTWeb.conFile");
    but I don't know where to declare the property in Bea9.
    Can anybody help?
    Best regards
    Peter

    getRealPath can return null if the resource is in an archived WAR. Can you use getResourceAsStream instead?
    You can declare system properties with -D flags on the java command-line you use to boot a server.
    Of if you wanted to do it in code, you could run a startup class which is configured to run before application deployment and call System.setProperty there.
    -- Rob
    WLS Blog http://dev2dev.bea.com/blog/rwoollen/

  • Error reading in file data on second entry and save of the data

    Hi,
    I'm trying to write a class that will save two integers and a string to a text file, which can later be searched. Both integers and the string are input by the user in the main class via the keyboard. The file is saved as follows,
    100 1
    901,111,offer releaseThe first line represents the maximum number of videos, and the current number of videos in the list. The second integer on the first line is automatically incremented to represent the correct number of video copies.
    When the test main class is run again to allow the user to enter a second line of data, it returns with the following error,
    Error in SimpleInput.readInt() - digit expected
    ,111,offer releaseWhy is it unable to find the first integer on the second line?
    My constructor for the class is as follows,
    public Video(int refNum, int titlerefNum, String filmOffer) {
            referenceNumber = refNum;
            titleReferenceNumber = titlerefNum;
            String[] words = filmOffer.split(",");
            videoOffer = words[0];
        }and my test main class is,
    import simplejava.*;
    import videos.*;
    import java.io.*;
    public class AddVideo {
        public static void main(String[] args) {
            //String film, actor1, actor2, director, title;
            int videocodeNum, titlecodeNum;
            String currentvideoOffer;
            SimpleReader keyboard = new SimpleReader();
            SimpleWriter screen = new SimpleWriter();
            SimpleReader inFile = new SimpleReader("title_test.txt");
            SimpleReader inFile2 = new SimpleReader("video_test.txt");
            TitleList titles = new TitleList(inFile);
            VideoList videos = new VideoList(inFile2);
            videocodeNum = keyboard.readInt("Reference Code for the Video?");
            titlecodeNum = keyboard.readInt("Reference Code for the Title?");
            currentvideoOffer = keyboard.readLine("Current Video Offer Code?");
            videos.add(new Video(videocodeNum, titlecodeNum, currentvideoOffer));
            screen.println(videos);
            Title search = titles.lookUp(titlecodeNum);//searches the title_test.txt file to find
            if (search == null)//the title code for the relevant number.
                screen.println("Not found");
            else screen.println(search);
            SimpleWriter outFile = new SimpleWriter("video_test.txt");
            videos.saveTo(outFile);
            outFile.close();
    }Any help or advice appreciated!!

    Hi,
    I'm trying to write a class that will save two integers and a string to a text file, which can later be searched. Both integers and the string are input by the user in the main class via the keyboard. The file is saved as follows,
    100 1
    901,111,offer releaseThe first line represents the maximum number of videos, and the current number of videos in the list. The second integer on the first line is automatically incremented to represent the correct number of video copies.
    When the test main class is run again to allow the user to enter a second line of data, it returns with the following error,
    Error in SimpleInput.readInt() - digit expected
    ,111,offer releaseWhy is it unable to find the first integer on the second line?
    My constructor for the class is as follows,
    public Video(int refNum, int titlerefNum, String filmOffer) {
            referenceNumber = refNum;
            titleReferenceNumber = titlerefNum;
            String[] words = filmOffer.split(",");
            videoOffer = words[0];
        }and my test main class is,
    import simplejava.*;
    import videos.*;
    import java.io.*;
    public class AddVideo {
        public static void main(String[] args) {
            //String film, actor1, actor2, director, title;
            int videocodeNum, titlecodeNum;
            String currentvideoOffer;
            SimpleReader keyboard = new SimpleReader();
            SimpleWriter screen = new SimpleWriter();
            SimpleReader inFile = new SimpleReader("title_test.txt");
            SimpleReader inFile2 = new SimpleReader("video_test.txt");
            TitleList titles = new TitleList(inFile);
            VideoList videos = new VideoList(inFile2);
            videocodeNum = keyboard.readInt("Reference Code for the Video?");
            titlecodeNum = keyboard.readInt("Reference Code for the Title?");
            currentvideoOffer = keyboard.readLine("Current Video Offer Code?");
            videos.add(new Video(videocodeNum, titlecodeNum, currentvideoOffer));
            screen.println(videos);
            Title search = titles.lookUp(titlecodeNum);//searches the title_test.txt file to find
            if (search == null)//the title code for the relevant number.
                screen.println("Not found");
            else screen.println(search);
            SimpleWriter outFile = new SimpleWriter("video_test.txt");
            videos.saveTo(outFile);
            outFile.close();
    }Any help or advice appreciated!!

  • Read xml file from jsp/servlet

    Hi all,
    I am a new comer to jsp and really appreciate if someone can help me on this:
    I will like to use a xml file to control access to my web app instead of using a database. Let say user.xml that will contains user name and password. Questions:
    1. where should I put this file? Under WEB-INF?
    2. In my jsp or servlet, how do i read the xml file, i mean how to i refer to the file (depend on question 1 as where the file should be placed)?
    Thank you very much.
    Sim

    Hi jlsim,
    you can place the xml file where you want, but remember that placing it under /WEB-INF is the most security way.
    I had a similar problem and I placed the xml file under /WEB-INF directory.
    To refer to it I did something like this:
    String realPath=getServletContext().getRealPath("WEB-INF/xml/workspaces.xml");//obtain the real path
    File f=new File(realPath);//obtain an instance of your file usable
    //to create an InputStream

  • Read binary file information from servlet - from database accessor method

    Okay, I have been working on this for awhile now and I just plain dont know what I am doing. Could someone please help me? I cannot find any examples through google or the forums for this specific type of situation( as in a servlet calls a method which gets binary file from a database).
    - How do I get the inputStream into the servlet so that I can read it?
    - Why am I getting the error message that OutputStream has already been called?
    If someone could give me direction or simply tell me what I should look up - I would really really appreciate it.
    The Servlet
    response.setContentType("application/msword");
    response.setHeader("Content-disposition","attachment; filename="+ file + ext);
    OutputStream os = response.getOutputStream();
    OOT openAttachments = searchInfo.openAttachments(newID, oot, ootNum, file, ext, os);
    InputStream is2 = oot.getIs();
        byte b[] = new byte[16384];
        int numBytes;
            while((numBytes=is2.read(b))!=-1){
                os.write(b,0,numBytes);
                System.out.println("is - in while" + is);
            is2.close();
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/ootMain.jsp?newID="+newID);
    dispatcher.forward(request, response);
            os.flush();
            os.close();
    The Method
    public OOT openAttachments(String newID, OOT oot, String ootNum, String file,
                               String ext, OutputStream os) {
        this.conn = database.SybaseDAO.grabConnection();
        String query = " edited for space'";
        state = conn.createStatement();
        rs = state.executeQuery(query);
            if(rs.next()){
               InputStream is = rs.getBinaryStream(2);
               oot.setIs(is);
               System.out.println("is - in while" + is);
               is.close();
    Error Messages
    (is - in while - method)    sun.jdbc.odbc.JdbcOdbcInputStream@c02a
    (is2 - after - servlet)      sun.jdbc.odbc.JdbcOdbcInputStream@c02a
    IOException: java.io.IOException: InputStream is no longer valid - the Statement
                                      has been closed, or the cursor has been moved
    Mar 14, 2005 9:53:19 AM org.apache.catalina.core.ApplicationDispatcher invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    java.lang.IllegalStateException: getOutputStream() has already been called for this responseThanks for your help/time -
    Crystal

    Here is the entire exception:
    Mar 16, 2005 9:32:44 AM org.apache.catalina.core.ApplicationDispatcher invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    java.lang.IllegalStateException: getOutputStream() has already been called for this response
         at org.apache.catalina.connector.Response.getWriter(Response.java:596)
         at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:161)
         at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:111)
         at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:122)
         at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
         at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:182)
         at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
         at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
         at org.apache.jsp.ootMain_jsp._jspService(org.apache.jsp.ootMain_jsp:596)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:302)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:246)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:682)
         at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:581)
         at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:501)
         at oot.display_files.doGet(display_files.java:63)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:106)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:576)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
         at java.lang.Thread.run(Thread.java:595)
    Mar 16, 2005 9:32:44 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet display_files threw exception
    java.lang.IllegalStateException: getOutputStream() has already been called for this response
         at org.apache.catalina.connector.Response.getWriter(Response.java:596)
         at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:161)
         at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:111)
         at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:122)
         at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
         at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:182)
         at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
         at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
         at org.apache.jsp.ootMain_jsp._jspService(org.apache.jsp.ootMain_jsp:596)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:302)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:246)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:682)
         at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:581)
         at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:501)
         at oot.display_files.doGet(display_files.java:63)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:106)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:576)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
         at java.lang.Thread.run(Thread.java:595)Line 63 is the include...

  • Read form file ok, try to write to same file : FileNotFound

    My application starts reads an xml file. When I try to write back to the XML file I get
    javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:\C:\Documents%20and%20Settings\alzoid\My%20Documents\Netbeans%20Projects\Laptop\UserSettings.xml (The filename, directory name, or volume label syntax is incorrect)
    I did SOP for file.getAbsolutePath() before it read and writes and the ouput is the same:
    "C:\Documents and Settings\alzoid\My Documents\Netbeans Projects\Laptop\UserSettings.xml"
    Here is the code that reads (works):
    public void fillToFile() {
            xmlFile = new File(TO_FILE_NAME);
            try {
                if(xmlFile.exists()) {
                    setToPocketPC(db.parse(xmlFile));
                } else {
                    createToPocketPC();
            } catch (SAXException se) {
                       se.printStackTrace();  
            } catch (IOException ioe) {
                ioe.printStackTrace();
        }Here is the code that throws the exception:
    private void writeDocumentToFile(Document doc,String fileName){
           try {
            xmlFile = new File(fileName);  
            System.out.println(xmlFile.getAbsolutePath());
            source = new DOMSource(doc);
            result = new StreamResult(xmlFile);
            transformer.transform(source, result); //fails here
            xmlFile = null;
            source = null;
            result = null;
           } catch (TransformerConfigurationException tce) {
               tce.printStackTrace();
           } catch (TransformerException te) {
               te.printStackTrace();
           } /*catch (IOException ioe) {
               ioe.printStackTrace();
        }The strange thing is I tested the read/write last week and it worked. I did not change any code. If I copy the file:\c:\Documents%20and%20Settings.... Path into windows explorer it finds the file.
    Any suggestions?
    Thanks
    Al

    I'm not sure why either, though the API docs mention "takes File to populate a StreamResult", which really does not make any sense. The File would be populated by the StreamResult. The way it is written would only make sense, at least to me, if the File was being used as input.
    Glad I could help. Best of luck.
    - Saish

  • Reading a file on the server with a servlet

    How do you read a file with a servlet that is located on the server?
    I have tried several methods: here I have one of them:
    begin code
    String temp;
    temp = this.getServletContext().getRealPath(temp);
    in = new BufferedReader(new FileReader(temp));
    while(in.ready())
    bodytext=in.readLine();
    end code
    output: can't find file
    while I am 100% certain that the file is present at the location given in the String temp.
    Can someone help me please?

    I have to make a servlet that makes a menu structure. When I press a link, he asks my servlet to read a html file on the server. Then, he writes a submenu structure combined with the body part of the html code of the html file. For now, I have made it in JavaScript, but that doesn't work like I want it to. An example of what I mean, you can find at http://www.autismevlaanderen.be/vva
    It's in a foreign language(Dutch), but it's the structure that matters.

  • How to read xml file as shown below.

    Hello,
    I am using flash builder 4 and currently working on implementing AIR application.
    I need to read xml file data.
    Normal xml files are easy to read and i am much more aware of it.
    But can any one have idea how to read XML file which is given below.
    <node>
    <key>ID</key>
    <integer>1</integer>
    <key>Name</key>
    <string>Dhwani</string>
    <key>Postno</key>
    <integer>20</integer>
    <key>deskname</key>
    <string>flex</string>
    <key>empid</key>
    <integer>25</integer>
    <key>projectname</key>
    <string>abc</string>
    </node>
    Here i have xml file in form of key value pair. <key> node shows name of the key and after that <integer> or <string> node are the value for that specific key.
    if i select node.key then it shows me all the keys. and from that i cant make out what is the value for key ID.
    Is there any way to take first node and then second. i mean first i ll take value of key and store it into some arraycollection. and then value will be stored.
    Any help is appreciated.. Looking for positive reply.
    Thanks
    Dhwani

    There are different methods to access XML data which have pro's and cons. Let us know more about what you want to do and we can help you.

  • Read BMP File Requires Absolute Path

    I noticed something today regarding the Graphics Formats, Read JPG File, Read PNG File and Read BMP File vi's. It seems that when reading a JPG or PNG file, a relative path is OK, but when reading a BMP file, an absolute path is required. When the path only contains the filename, it returns:
        Error 1430
        "Open/Create/Replace File in Read BMP File Data.vi->Read BMP File.vi->ReadImageFileTest.vi"
    I tried a simple test that uses either the relative or absolute path, trying to read 3 different files in the same directory as the VI. Only the Read BMP File errors. Of course, the simple work around is to always use the full pathname to a file. Is this only on my system? Is this a known bug or feature or expected behavior?
    I'm using LabVIEW 8.2 on Windows XP.
    Thanks!
    B-)
    Message Edited by LabViewGuruWannabe on 11-05-2007 11:06 PM
    Attachments:
    ReadImageFileTest-FPgood.PNG ‏30 KB
    ReadImageFileTest-FPbad.PNG ‏26 KB
    ReadImageFileTest-BD1.PNG ‏48 KB

    Missed this on the first post:
    Message Edited by LabViewGuruWannabe on 11-05-2007 11:10 PM
    Attachments:
    ReadImageFileTest-BD.PNG ‏48 KB

  • How to read svg file by  Xerces2 -j  java

    How can we read svg file data by using Xerces2 -j java

    Hi Dharma,
    There is a new beta release for [java-libpst|http://code.google.com/p/java-libpst/] that adds 32bit (ANSI) PST support.

  • How to read a file as an input stream after it's posted in an HTML form ?

    Hello,
    I want to read client file after it's posted in an HTML form. But, I don't want to upload it to filesystem or database. I want to read posted file as an input stream. How can I do that ?
    thanks in advance...

    A couple of things. If you have a FILE field in your form, the enctype of the form must be multipart/form-data. Check this link
    http://www.htmlhelp.com/reference/html40/forms/form.html
    Also, when a file is uploaded you cannot use the regular methods to get at the name/value pairs or the file itself. You'll have to use a utility like MultiPartRequest or write your own based on the RFC for Multipart requests.
    http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html
    You will need some temporary file system to store this and then delete it when you are done with it.
    hth

  • Form jsp data are not going to servlet

    Hi guys
    i got a problem doing my uni assignment. this is an assignment about taking data from a html webpage. then storing the data in a xml document through java servlet. the problem is when i try to pass tha data through servlet it doesnt work. the error message it give is following:
    Error: 500
    Location: /BookingApp/servlet/BookingProcessServlet
    Internal Servlet Error:
    java.lang.NullPointerException
         at BookingProcessServlet.generateDOM(BookingProcessServlet.java:119)
         at BookingProcessServlet.doPost(BookingProcessServlet.java:294)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
         at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
         at org.apache.tomcat.core.Handler.service(Handler.java:235)
         at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
         at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
         at java.lang.Thread.run(Thread.java:479)
    the coding in the corresponding linnes mentioned in the error message i have givan below:
    for at BookingProcessServlet.generateDOM(BookingProcessServlet.java:119)
              BookingBean [] bookinglist = (BookingBean []) bookings;
         >>>>     for(int i=0; i<bookinglist.length; i++) >>>> this the line where the error is shown
                   if (bookinglist[i] != null)
                        bookingcount++;
                   else
                        continue;
    for at BookingProcessServlet.doPost(BookingProcessServlet.java:294)
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         String action = request.getParameter("action");
         if (action != null && action.equals("Back"))
              if(insertBookingToSession(request))
                   response.sendRedirect("../jsp/deafault.html");
              else
              response.sendRedirect("../jsp/ListFullError.html");
         else if (action != null && action.equals("Confirm"))
              Document newDOMTree = generateDOM(request);
              generateXMLDocument(newDOMTree);
              HttpSession session = request.getSession(true);
              session.removeAttribute("BookingList ");
              response.sendRedirect("../jsp/confirm.html");
    Please this is is urgent. the problem is I am new in JSP and Java Servlet programming. So I dont have any idea what is this problem.
    please reply as soon as possible. thank u guys.
    waiting for the replies.

    hei chk d ff code : this code works i tried dis before i gave it to u
    <HTML>
    <%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    <%
    if(request.getParameter("submit")!=null){
         String filename="C:/Program Files/Apache Group/Tomcat 4.1/webapps/lbc/xml/test.xml";
         String xmlString = "<xml>";
         Enumeration enums = request.getParameterNames();
         while(enums.hasMoreElements()){
         String tagname= (String) enums.nextElement();
         xmlString = xmlString +"<"+tagname+">";
         xmlString = xmlString +request.getParameter(tagname);
         xmlString = xmlString +"</"+tagname+">";
         System.out.println(xmlString);
         try {
         BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filename)));
         bos.write(xmlString.getBytes());
         bos.flush();
         bos.close();
         catch (IOException ioe) {
         System.out.println(ioe.toString());
    response.sendRedirect("Confirmation.jsp");     
    %>
    <TABLE CELLSPACING="1" CELLPADDING="0" BORDER="0" WIDTH="50%">
    <FORM method="post" NAME="test">     
         <TR>
         <TD BGCOLOR="#94976E">First Name:</TD>
         <TD><input type="text" name="fname"/></TD>
         </TR>
         <TR>
         <TD BGCOLOR="#94976E">Last Name</TD>
         <TD><input type="text" name="lname"/></TD>
         </TR>
         <TR>
         <TD BGCOLOR="#94976E">Middle Initial</TD>
         <TD><input type="text" name="iname"/></TD>
         </TR>
         <tr>
         <td colspan="2" align="center"><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Send"/></td>
         </tr>
    </FORM>
    </TABLE>
    </HTML>

Maybe you are looking for