请告诉我在这个jsp程序中我在哪里犯了错误

时间:2009-02-10 10:15:36

标签: java debugging jsp

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

请告诉我如何纠正。

4 个答案:

答案 0 :(得分:1)

我说罪魁祸首是

File outputFile = new File( generate.xml );

我怀疑您可能希望将该字符串包装在引号(“”)中,否则它将被视为标识符,运行时将不知道任何内容。

答案 1 :(得分:1)

File outputFile = new File(generate.xml); 

我猜generate.xml应该在双引号内,至少是我的两分钱。

说真的,请格式化你的代码,使它看起来更好,否则它太难读了。

答案 2 :(得分:1)

哇这真是难以理解!

罪行是

File outputFile = new File(generate.xml);

假设generate.xml是文件名,您需要引用它,因为它是一个String

File outputFile = new File("generate.xml");

答案 3 :(得分:0)

generate.xml需要在引号中。它不认为它是一个字符串,它认为你的意思是有一个名为“generate”的对象带有“xml”属性。