简体   繁体   中英

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM