2010-06-24 77 views

回答

4

是的,您可以使用alternatedocroot属性(在Glassfish中)来提供战争以外的文件(如图片)。

这个属性可以在sun-web.xml中 文件或 太阳web-app元素在 虚拟服务器的元素domain.xml文件

见的子元素在这里:http://docs.sun.com/app/docs/doc/820-4496/geqpl?l=en&a=view

例如:

<property name="alternatedocroot_1" value="from=/images/* dir=/usr/gifs"/> 
+0

这看起来像什么我要找的。谢谢。 – Bogdan 2010-06-24 13:31:57

1

你可以添加一个servletŧ o您的应用程序读取文件。

实例(需要错误处理)

public class FileDownloadServlet extends HttpServlet { 

     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 

     String filename = request.getParameter("filename"); 
     InputStream is; 
     try { 
      is = FileUtils.openInputStream(new File(filename)); 
      byte[] buf = new byte[ 8192 ]; 
      int bytesRead; 
      while ((bytesRead = is.read(buf)) != -1) 
       os.write(buf, 0, bytesRead); 
     } 
     catch(...) { 
     } 
     finally { 
      is.close(); 
      os.close(); 
     } 
     response.setContentType("application/octet-stream"); 
     } 
    } 
+0

+1是一个不错的选择。谢谢 ;) – Bogdan 2010-06-24 13:32:54

相关问题