我從絕對路徑中查看了BalusC的定製下載servlet的代碼(請參閱http://balusc.blogspot.com/2007/07/fileservlet.html#FileServletServingFromAbsolutePath)。我不是一個Java Web開發專家,所以我會很喜歡,如果什麼時候init方法被調用有人能explainme代碼自定義下載servlet
private String filePath;
// Actions ------------------------------------------------------------------------------------
public void init() throws ServletException {
// Define base path somehow. You can define it as init-param of the servlet.
this.filePath = "/files";
// In a Windows environment with the Applicationserver running on the
// c: volume, the above path is exactly the same as "c:\files".
// In UNIX, it is just straightforward "/files".
}
的一部分?爲什麼我們需要在init方法中設置filePath?
我有一個XHTML(Mojarra + IceFaces)類似下面的代碼,很好用。我的頁面丟失下載這是由outputLink
標籤
<ice:tree id="tree"
value="#{treeBean.model}"
var="item"
hideRootNode="false"
hideNavigation="false"
>
<ice:treeNode>
<f:facet name="icon">
<ice:panelGroup style="display: inline">
<h:graphicImage value="#{item.userObject.icon}" />
</ice:panelGroup>
</f:facet>
<f:facet name="content">
<ice:panelGroup style="display: inline-block">
<ice:outputLink value="#{item.userObject.filePath}">
<ice:outputText value="#{item.userObject.fileName}"/>
</ice:outputLink>
</ice:panelGroup>
</f:facet>
</ice:treeNode>
</ice:tree>
引用我支持bean中我有兩個字段fileName
和filepath
(只是在filewith擴展名,比如Image.jpeg的名稱)的文件只是部分(服務器中文件的ABSOLUTE路徑)。最後我想用自定義servelet下載文件,我該怎麼做?
乾杯,
UPDATE
假設MI基礎-dir是/SRC
和目錄下,我有我所有的XHTML頁面和WEB-INF和META-INF和方法,另外我有一個目錄所謂數據文件下的數據文件,我有以下結構
--dataFiles
|----Enterprise1
| |--User1
| | |--goodFiles
| | | |--ok.txt
| | |--badFiles
| | |--bad.txt
| |--User2
| | |--goodFiles
| | | |--ok.txt
| | |--badFiles
| | |--bad.txt
|----Enterprise2
|--User1
| |--goodFiles
| | |--ok.txt
| |--badFiles
| |--bad.txt
|--User2
|--goodFiles
| |--ok.txt
|--badFiles
|--bad.txt
這就是我如何呈現樹與ICEfaces的,我只是有後臺bean中的文件名(即ok.txt或bad.txt),但我無法弄清楚如何通過樹中的鏈接下載指向的文件。
我因爲這個問題成了方式過於寬泛和本地化的,我沒有看到你真正的問題了自己刪除了。僅僅花費更多的時間來計算/猜測你的具體問題是不值得的。 – BalusC
認爲你是對的。但是,無論如何,在您的建議下我解決了我的問題。 – BRabbit27