2009-02-11 71 views
0

我创建了两个文件 1)index.html 2)player.jsp 我使用的是Tomcat服务器。 在index.html中,我在表单中创建了一些复选框并分配了值... 单击提交后,我将这些值转发给player.jsp ... 在player.jsp中,我动态生成了一个名为“generate”的xml文件。 xml“。 此XML文件根据用户请求而变化。 对于每个新的请求xml文件都应该被覆盖。 如果在表单中选中了一个复选框,则generate.xml中的结构将采用一种形式 (如果在表单中选中了两个复选框,则generate.xml中的结构将为另一种形式)。 我嵌入在jsp页面Flash播放器这需要generate.xml为输入,播放歌曲... 的player.jsp的代码是如何覆盖保存在上下文目录中的文件

<%@ page import="java.io.*" %> 
<%@ page contentType="text/html;charset=ISO-8859-1" %> 
<% 
int iLf = 10; 
char cLf = (char)iLf; 
String myfile = application.getRealPath("/") + "generate.xml"; 

File outputFile = new File(myfile); 
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"); 

    out.println("<html><body><h1>hello</h1></body></html>"); 

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

    %> 
<object type="application/x-shockwave-flash" width="400" height="170" 
      data="xspf_player.swf?playlist_url=generate.xml"> 
      <param name="movie" value="xspf_player.swf?playlist_url=generate.xml" /> 

</object> 

我的问题是,在我的本地系统这一切都工作正常 和generate.xml每次都会覆盖每个新的请求... 我创建了ROOT.war并在www.eatj.com上传了这个文件 这里当第一个请求被提交时generate.xml根据请求创建的文件.. for this generate this.xml is NOT OVERW RITTEN。 播放器将第一个请求生成的generate.xml文件提交给所有新请求。 请帮我做的改动任何代码,这样我可以覆盖以前生成的XML文件..

回答

1

的方法getRealPath()下不战争工作,并且将返回,公平。您必须使用相对路径才能使其工作。 Request.getResourceAsStream()是一个更好的选择。正因为如此,使用getRealPath()非常不鼓励。

将帖子

Found a thread of coderanch确认我怀疑。