2010-06-24 76 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

相關問題