1

次のサーブレットは、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**を出力します

以下は、ローカルホストとローカルからそれぞれアクセスした html のスナップショットです。

ここに画像の説明を入力

ここに画像の説明を入力

4

0 に答える 0