musicking123
musicking123

Reputation: 3445

how to save the generated xml file using jsp?

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/">
   <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>

Upvotes: 0

Views: 1997

Answers (1)

Ola Bini
Ola Bini

Reputation: 704

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\"".

Upvotes: 3

Related Questions