如何在页面源中输出文件内容(来自数据库)?
我正在开发 Spring WebFlow / JSF Web 应用程序。我需要开发管理面板,管理员可以在其中上传一些文件并使用这些文件作为片段构建页面内容。我希望我描述得很好。为此,我创建了 Spring MVC 控制器,其映射如下所示。它从数据库输出文件(图像,.xhtml)。如何使用该控制器将文件包含在页面源中?
@RequestMapping("/file")
public void getFileContent(@RequestParam("id") Integer id, HttpServletResponse response) throws IOException {
File f = fileDAO.get(id);
response.setContentType(f.getMime());
IOUtils.write(f.getData(), response.getOutputStream());
}
这不起作用:
<ui:include src="#{request.contextPath}/app/file?id=6" />
I'm working on Spring WebFlow / JSF web-app. I need to develop administration panel where admin can upload some files and build page content using this files as fragments. I hope I described it well. To do that, I've created Spring MVC controller with mapping like below. It output files from database (images, .xhtml). How to use that controller to include files on page source ?
@RequestMapping("/file")
public void getFileContent(@RequestParam("id") Integer id, HttpServletResponse response) throws IOException {
File f = fileDAO.get(id);
response.setContentType(f.getMime());
IOUtils.write(f.getData(), response.getOutputStream());
}
This doesn't work:
<ui:include src="#{request.contextPath}/app/file?id=6" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSF/Facelets 包括在服务器端运行,而不是在客户端运行。
接受服务器端路径,而不是 Web URL。 Spring 侦听客户端 (HTTP) 请求,而不是像 JSF 那样侦听服务器端资源解析。最好的选择是使用自定义 Facelets
ResourceResolver
相反,它检查传入路径,将文件存储在临时存储上并返回其URL
,或只是为了替换
by HTML因为您似乎想使用 Spring 来实现此目的。
JSF/Facelets includes runs server side, not client side.
<ui:include>
accepts server side paths, not web URLs. Spring listens on client (HTTP) requests, not on server side resource resolvings as JSF does.Your best bet is using a custom Facelets
ResourceResolver
instead which checks the incoming path, stores the file on temp storage and returns itsURL
back, or just to replace<ui:include>
by HTML<iframe>
since you seem to want use Spring for this.