我没做过JAVA WEB 开发,现在需要提供一个类似于http://123.234.345.456/soft/update/AAA.zip
的URL地址给别人下载AAA.zip用。请问这个服务器怎么搭建?我安装好了jdk1.6和apache-tomcat-7.0.19-windows-x86,配置好了环境变量。
在Eclipse装了web开发的插件,新建了一个web项目mywebpro,添加了一个index.jsp
目前可以通过http://123.234.345.456:8080/mywebpro 正常访问index.jsp请问下面是怎么个做法,能让别人通过一个url下载我的AAA.zip?

解决方案 »

  1.   

    你这头像不是eclipe版版猪的么??参见这个博客吧
    http://www.cnblogs.com/ungshow/archive/2009/01/12/1374491.html
      

  2.   

    你这个好像是给客户端口用来下载服务器上文件用的,但我现在是要在服务器上发布这个AAA.zip
    PS:头像是我自己从游戏中截图做的,几年前就在用了。
      

  3.   

    1。在你的tomact /webapps/mywebpro  创建这些文件夹 /soft/update/然后下边放AAA.zip文件。2。在你的index.jsp 中加入
       <a href="down.jsp?filename=AAA.zip"> AAA文件</a>3.将down.jsp 放至mywebpro 下.内容为<%
     response.reset();//可以加也可以不加
        response.setContentType("application/x-download");
        
        String filename=request.getParameter("filename");
        String filenamedownload ="/soft/update/"+filename;
        System.out.println(filenamedownload);
        String filenamedisplay =filename;//系统解决方案
        filenamedisplay = URLEncoder.encode(filenamedisplay,"UTF-8");
        response.addHeader("Content-Disposition","attachment;filename=" + filenamedisplay);    OutputStream output = null;
        FileInputStream fis = null;
        try
        {
            output  = response.getOutputStream();
            fis = new FileInputStream(filenamedownload);        byte[] b = new byte[1024];
            int i = 0;        while((i = fis.read(b)) > 0)
            {
                output.write(b, 0, i);
            }
            output.flush();
        }
        catch(Exception e)
        {
            System.out.println("Error!");
            e.printStackTrace();
        }
        finally
        {
            if(fis != null)
            {
                fis.close();
                fis = null;
            }
            if(output != null)
            {
                output.close();
                output = null;
            }
        }
    %>
      

  4.   

    写个servlet将  zip文件的网络路径返回给浏览器就行了