views:

180

answers:

5
<%@ page import="java.io.*" %>
<%-- <%@ page contentType="text/html;charset=ISO-8859-1" %> --%>
<%
int iLf = 10;
char cLf = (char)iLf;
File outputFile = new File(generate.xml);
outputFile.createNewFile();
FileWriter outfile = new FileWriter(outputFile);
outfile.write(" <?xml version='1.0' encoding='UTF-8'?> "+cLf);
outfile.write(" <playlist version='1' xmlns = 'http://xspf.org/ns/0/' > " +cLf);
outfile.write(" <title>My Band Rocks Your Socks</title> "+cLf); 
outfile.write("<trackList>"+cLf); 
%>
 <%! String[] sports; %>
 <%
    sports = request.getParameterValues("sports");
    if (sports != null)
    { 
         for (int i = 0; i < sports.length; i++)
         { 
              // outfile.writeln (sports[i]); 
           String total=sports[i];
           String[] sa=total.split("[,]");
              // String[] sub=new String();
           outfile.write("<track>"+cLf);
           for (int j=0;j<sa.length;j++)
              {
             // outfile.writeln(sa[j]);
                // outfile.writeln("sa["+j+"]="+sa[j]);
             if( j == 0)
             {
               outfile.write("<location>" + sa[0] +"</location>"+cLf); 
             }
                else if (j == 1)
                     {
                        outfile.write("<image>" + sa[1] +"</image>"+cLf); 
         }
                     else if( j==2)
                          {
                            outfile.write("<title>" + sa[2] +"</title>"+cLf);
                       }

               }// end of inner for loop()       
               outfile.write("</track>"+cLf);
         //outfile.writeln();
      }// end of outer for()
    } 
    //else outfile.writeln ("<b>none<b>");

  outfile.write(" </trackList> "+cLf);
  outfile.write(" </playlist> "+cLf);
  outfile.close();

  %>

The exception thrown is

An error occurred at line: 7 in the jsp file: /sports3.jsp
generate.xml cannot be resolved to a type
4: <%
5: int iLf = 10;
6: char cLf = (char)iLf;
7: File outputFile = new File(generate.xml);
8: outputFile.createNewFile();
9: FileWriter outfile = new FileWriter(outputFile);
10: outfile.write(" <?xml version='1.0' encoding='UTF-8'?> "+cLf);


please tell me how to rectify.

+1  A: 

I'd say the culprit was

File outputFile = new File( generate.xml );

I suspect you probably want to wrap that string in quote marks (""), otherwise it'll be treated as an identifier, which the runtime won't know anything about.

Rob
+1  A: 
File outputFile = new File(generate.xml);

I guess generate.xml should be within double quotes, atleast that's my two cents.

Seriously, please format your code so that it appears better, otherwise its too tough to read.

Shivasubramanian A
+1  A: 

wow this is just unreadable !

the guilty line is

File outputFile = new File(generate.xml);

assuming generate.xml is the file name, you need to quote it as it is a String

File outputFile = new File("generate.xml");
chburd
A: 

generate.xml needs to be in quotes. It doesn't see it as a string, it thinks you mean there's an object called "generate" with an "xml" property.

Neil Barnwell
A: 

hey thank you very much guys... i got the solution...

musicking123
Congratulations!! Now it will be interesting to watch whose answer you would choose as the accepted answer. ;-)
Shivasubramanian A