<%@ 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();

  %>


抛出的异常是

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);




请告诉我如何纠正。

最佳答案

我说罪魁祸首是

File outputFile = new File( generate.xml );


我怀疑您可能想将该字符串包装在引号(“”)中,否则它将被视为标识符,运行时对此一无所知。

09-25 22:04