以下servlet创建一个名为 Shared 的目录,然后将视频复制到此目录中。接下来,它会显示该链接以下载此视频。但是当我点击链接时,没有任何反应。为什么是这样 ?
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
String path = request.getServletContext().getRealPath("/") + "Shared/" + "sweet-love-story-that-might-make-your-day[www.savevid.com].3gp";
path = path.replace("\\","/");
try {
File f = new File(request.getServletContext().getRealPath("/") + "Shared/");
if(!f.exists()) {
f.mkdir();
// now copy the animation to this directory
} else {
System.out.println("directory already made");
}
writer.println("<html> <head> <title> </title> </head>");
writer.println("<body>");
writer.println("<a href=\"file:///" + path + "\"" + ">Click to download</a>");
writer.println("</body>");
writer.println("</html>");
}catch(Exception exc) {
exc.printStackTrace();
}
}
具有讽刺意味的是,当我写一个与视频(在共享中)在同一目录中的html时,我可以下载/看到视频。当我通过localhost
访问链接时,为什么链接不起作用?
(我正在使用Tomcat)
**注意:语句request.getServletContext().getRealPath("/")
打印W:\ UnderTest \ NetbeansCurrent \ App-1 \ build \ web **
以下是分别从localhost和本地访问的html快照。
和