写了一个程序,在ECLIPSE中启动TOMCAT,可以读取网络路径中的文件. 如果打成WAR包,发布到TOMCAT的WEBAPPS目录下,就不可以访问了 请问这是什么原因?代码,访问的路径都是一样的. public class FilePathTest extends HttpServlet { private static final long serialVersionUID = -3444899789742803895L; public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8"); String path = request.getParameter("path"); File file = new File(path); response.getWriter().write("路径:"+file.getPath()+" <br>"+"测试结果:"+(file.isDirectory()||file.isFile()));
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request,response);
} }
throws ServletException, IOException { request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8"); String path = request.getParameter("path"); File file = new File(path); response.getWriter().write("路径:"+file.getPath()+" <br>"+"测试结果:"+(file.isDirectory()||file.isFile()));
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request,response);
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货