tags:

views:

393

answers:

2

hi

i have generated xml file using jsp,but i want the generated xml file should be saved as a file. my code is

   <?xml version="1.0" encoding="UTF-8"?>
   <%@ page contentType="text/xml;charset=ISO-8859-1" %>
   <playlist version="1" xmlns = "http://xspf.org/ns/0/"&gt;
   <title>My Band Rocks Your Socks</title>
   <trackList>
   <%! String[] sports; %>
   <%
    sports = request.getParameterValues("sports");
    if (sports != null)
    { 
         for (int i = 0; i < sports.length; i++)
         { 
              // out.println (sports[i]); 
           String total=sports[i];
           String[] sa=total.split("[,]");
              // String[] sub=new String();
           out.print("<track>");
           for (int j=0;j<sa.length;j++)
              {
             // out.println(sa[j]);
                // out.println("sa["+j+"]="+sa[j]);
             if( j == 0)
             {
               out.print("<location>" + sa[0] +"</location>"); 
             }
                else if (j == 1)
                     {
                        out.print("<image>" + sa[1] +"</image>"); 
         }
                     else if( j==2)
                          {
                            out.print("<title>" + sa[2] +"</title>");
                       }

               }// end of inner for loop()       
               out.print("</track>");
         //out.println();
      }// end of outer for()
    } 
    //else out.println ("<b>none<b>");
  %>
  </trackList>
 </playlist>
+1  A: 

Yes, you can. The way to do it is basically to set an extra header - which you can do on the response object.

The header to set is called Content-Disposition and the value should be something like "attachment; filename=\"foo.xml\"".

Ola Bini
hi Bini,I added <% response.setHeader("Content-Disposition", "attachment; filename=\"playlist.xml\""); %> worked fine but it is prompting to save the file in a particular location..cant i directly have a code to directly store it in one location and overwrite the same file in the next run.
musicking123
+1  A: 

Hi musickin,

did you get any solution, coz i am also having the same requirement. i really hope you will reply to this post

thanks in advance vishal

vishla