hi, i am new to JSP and need ur help. on the client end, i have created a HTML form. now, on the server, i want to use JSP to create a XML file that contains the user selections made via the HTML form. this XML file is later used by other servlets in the server to extract data. how can this be done? thanks in advance.
Have you found a way to actually write out the XML document using the Sun API? Xerces offers a nice API for doing that, so you won't have to iterate over all the elements by hand and write them:
doc is a DocumentImpl f is a File logger is a Logger I set the line separator to Windows format here for my own sanity. The files will in practice be used only by the machine (mostly Unix machines) but during testing I want to look at them myself and I'm using Windows as a workstation (with the Java stuff running on Unix so not forcing it to Windows would yield invalid line separators when opening the XML in Windows).
Joined: Mar 10, 2004
HI friends, thank u very much for the quick reply. i feel i probably need a little more clarification. actually in the HTML form, instead of specific values like "name","age" etc, i have included an entire text file ie the tag looks like: <selct name="sel" onchange="loadfile()"> <option value="D:\program\aaa.txt>file1 <option value="D:\program\bbb.txt>file2 </select> now i want the generated XML file to have either 'file1' or 'file2' depending on what option the user selects. then the JSP needs to extract data from either aaa.txt or bbb.txt hope u understand what i need....
Joined: Nov 07, 2003
In this case, you may need to have one more hidden field for uploading the file to the server before you send out the request. This is because, even if a JSP get the value of "sel" as "C:\xxx\yyy.zzz", the JSP cannot read the file from your harddisk, cos JSP is resided in remote, not your machine! You should have a html form with the attribute enctype="multipart/form-data", such that the file will be uploaded. I dont know how JSP solely can perform the upload, as I use Struts to perform the upload. So, when Struts get the form, it knows where the file is located at the server, and use the info to get back the file. Nick.