我从绝对路径中查看了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