jac*_*ack 8 java spring portlet spring-mvc spring-portlet-mvc
我在为我@ActionMapping创建一个PDF文件.现在我想知道如何以保存/打开文件对话框的形式将这个pdf返回给用户?如果这一代人成功的话,我更喜欢这个显示下载链接.
我将spring-mvc 3.0.5与portlet结合使用.但是,如果有人有一些正常应用程序的指针,那么我可以从那里弄清楚.对于2.0,我读了一些关于扩展pdfgenerator类并在web.xml中进行修改的内容但是从现在开始我们只需要POJO ....
编辑:Adeel建议后的代码:
File file = new File("C:\\test.pdf");
response.setContentType("application/pdf");
try {
byte[] b = new byte[(int) file.length()];
OutputStream out = response.getPortletOutputStream();
out.write(new FileInputStream(file).read(b));
out.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "users/main";
Run Code Online (Sandbox Code Playgroud)
您可以直接将该文件写入您的文件中response writer,并且不要忘记更改contentType.例如,
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=something.pdf");
OutputStream out = response.getOutputStream();
out.write(pdfFileContentInBytes);
out.flush();
Run Code Online (Sandbox Code Playgroud)
嗯,我认为它HttpServletResponse是你拥有的,但事实并非如此.当您使用Portlet时,它是一个RenderResponse对象.通过互联网搜索后,我发现在这方面可能对您有所帮助的链接很少.
首先以Lotus Form Server Portlet为例,展示如何在配置portlet时允许多个mime类型portlet.xml.
这是Spring Portlet文档,它显示了我们如何使用portlet.xml配置portlet.它有一个关于mime-type的XML元素,看看你是否可以给出值application/pdf.
另一个想法是将参数更改为ActionResponse response,而不是RenderResponse response.我在这里有点模糊,不确定你的超级班级是什么?它是什么方法?等等....
对我来说,似乎问题是允许/不允许的mime-types用于portlet响应.
| 归档时间: |
|
| 查看次数: |
17016 次 |
| 最近记录: |