相关疑难解决方法(0)

使用.war文件部署时,为什么getRealPath()返回null?

getRealPath()返回本地系统中的实际路径,但在与.war文件一起部署时返回null .

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

out.println(myfile);    
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 = …
Run Code Online (Sandbox Code Playgroud)

java xml jsp java-ee

28
推荐指数
3
解决办法
6万
查看次数

标签 统计

java ×1

java-ee ×1

jsp ×1

xml ×1