tags:

views:

151

answers:

3

sports.jsp:

<?xml version="1.0" encoding="UTF-8"?>

<%@ page contentType="text/xml;charset=ISO-8859-1" %>
<% response.setHeader("Content-Disposition", "attachment; filename=\"playlist.xml\""); %>
<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>

This code is generating an xml file, but it is prompting me to mention the location where to save it.I want to create and store xml file at a particular location without any prompting and each time for the next input values the current xml file should be overwritten.

+1  A: 

You cannot do that due to security restrictions. You cannot get access of user system and start writing files without user's permission.

Bhushan
A: 

You're asking for a feature that no browser wants to provide, due to security risks. You don't want a browser to be able to overwrite an arbitrary file on the system with no user prompt.

If you really need to do this, you need to be running a signed Applet or Web Start application. With this, you have permission to write locally without a user prompt. If you don't want to purchase an official certificate, you can use a self-signed certificate to sign your JAR files. If you do this, the user will get a prompt when they encounter your application about the certificate. However, once the Applet/Web Start application is running, you have free reign to write locally.

Note: You need to edit your question to insert four blanks in front of each line of your JSP, so it will be correctly and automatically formatted by StackOverflow.

Eddie
A: 

hi thank you very guys for your information.

musicking123