Thijs Vonk 15 年之前 Hi Ray,I'm wondering if the last bit of code works. [...]res.addProperty( HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");[...]Because PortletResponseImpl does not implement addProperty properly... public void addProperty(String key, String value) { if (key == null) { throw new IllegalArgumentException(); }}(this code is from branch 5.0.x)(see also LEP-5828) 请登录以投票。 以……回复 取消 Brian Chan Thijs Vonk 15 年之前 LEP-5828 is a duplicate and was fixed about 3 weeks ago I think. It'll be in the next 5.0.x release. 请登录以投票。 以……回复 取消 Ray Augé Thijs Vonk 15 年之前 Just committed a fix!See http://support.liferay.com/browse/LEP-5828 请登录以投票。 以……回复 取消 Vivek N Kapse Ray Augé 15 年之前 I want to use this but couldn't figure out how to use it in my Struts Portlet. I am using Liferay 5.1.1. Should this be in action class or a jsp servlet or something else? Looking at the URL <portlet:resourceURL> couldn't understand how this would invoke the serveResource method. Can anyone give an elaborate explaination? Please. 请登录以投票。 以……回复 取消
Brian Chan Thijs Vonk 15 年之前 LEP-5828 is a duplicate and was fixed about 3 weeks ago I think. It'll be in the next 5.0.x release. 请登录以投票。 以……回复 取消
Ray Augé Thijs Vonk 15 年之前 Just committed a fix!See http://support.liferay.com/browse/LEP-5828 请登录以投票。 以……回复 取消 Vivek N Kapse Ray Augé 15 年之前 I want to use this but couldn't figure out how to use it in my Struts Portlet. I am using Liferay 5.1.1. Should this be in action class or a jsp servlet or something else? Looking at the URL <portlet:resourceURL> couldn't understand how this would invoke the serveResource method. Can anyone give an elaborate explaination? Please. 请登录以投票。 以……回复 取消
Vivek N Kapse Ray Augé 15 年之前 I want to use this but couldn't figure out how to use it in my Struts Portlet. I am using Liferay 5.1.1. Should this be in action class or a jsp servlet or something else? Looking at the URL <portlet:resourceURL> couldn't understand how this would invoke the serveResource method. Can anyone give an elaborate explaination? Please. 请登录以投票。 以……回复 取消
Denis Signoretto 14 年之前 Can you describe how can be used/overrided the method:public void serveResource(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ... }of MyStrutsPortletAction, write jsp tags and use configure Struts to download a file?Thanks,D. 请登录以投票。 以……回复 取消
Kuo Hsiung Chong 14 年之前 i try to set the content-disposition to reflect the filename but it failed.String contentDisposition = "attachment; filename=" + filename;resourceResponse.setProperty(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);Did anyone encounters this problem before? Any solution for it.(I try both setProperty and addProperty but still fail to display the correct filename) 请登录以投票。 以……回复 取消
Jose Antonio 14 年之前 Hi,I have a problem, i don't know how configure the files struts-config.xml and tiles-def.xml in Liferay 5.2.3.I'm using my portlet in EXT enveroiment.Thanks.Jose Antonio. 请登录以投票。 以……回复 取消
stefano flores 14 年之前 How I solvethis problem for JSF-portlet???http://stackoverflow.com/questions/2361765/problem-to-display-a-pdf-from-my-jsf-portlet-of-liferayHEEELLLLPPPPPP!!!! 请登录以投票。 以……回复 取消 Ray Augé stefano flores 14 年之前 See http://stackoverflow.com/questions/2361765/problem-to-display-a-pdf-from-my-jsf-portlet-of-liferay/2363832#2363832 请登录以投票。 以……回复 取消
Ray Augé stefano flores 14 年之前 See http://stackoverflow.com/questions/2361765/problem-to-display-a-pdf-from-my-jsf-portlet-of-liferay/2363832#2363832 请登录以投票。 以……回复 取消
alex wom 13 年之前 I'm using the example and it work for txt file and not for zip files. My code is in the following, and with zip files I cannot open that after download because the files seem corrupted... String xmlString = FileUtil.read(fileDirectory+fileName); HttpServletResponse response = PortalUtil.getHttpServletResponse(res); in = new ByteArrayInputStream(xmlString.getBytes()); String contentType = MimeTypesUtil.getContentType(fileDirectory+fileName); String extension = FileUtil.getExtension(fileName); if (extension.equalsIgnoreCase("zip")) contentType="application/zip"; res.setContentType(contentType); res.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate"); res.addProperty(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="+fileName); res.addProperty(HttpHeaders.CONTENT_ENCODING, "Binary"); OutputStream out = res.getPortletOutputStream(); in = new ByteArrayInputStream(xmlString.getBytes()); if (in == null) { out.close(); } else { byte[] buffer = new byte[4096]; int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } out.flush(); in.close(); out.close(); } } 请登录以投票。 以……回复 取消 Ray Augé alex wom 13 年之前 You're reading a potentially binary file into a string so yeah. it's gonna be corrupted.Stream the file right into the res, like so:InputStream in = new FileInputStream(new File(fileDirectory+fileName));The rest looks fine! 请登录以投票。 以……回复 取消
Ray Augé alex wom 13 年之前 You're reading a potentially binary file into a string so yeah. it's gonna be corrupted.Stream the file right into the res, like so:InputStream in = new FileInputStream(new File(fileDirectory+fileName));The rest looks fine! 请登录以投票。 以……回复 取消
Jiri Vanek 13 年之前 I'm not able to find dependencies for import javax.portlet.ResourceResponse;import javax.portlet.ResourceRequest;in my portal 2.0, maven, liferay 5.2.3 application 请登录以投票。 以……回复 取消 Jiri Vanek Jiri Vanek 13 年之前 and when I use instead of <dependency> <groupId>portlet-api</groupId> <artifactId>portlet-api</artifactId> <version>1.0</version> <scope>provided</scope> </dependency>the <dependency> <groupId>javax.portlet</groupId> <artifactId>portlet-api</artifactId> <version>2.0</version> </dependency>Liferay crashes. 请登录以投票。 以……回复 取消
Jiri Vanek Jiri Vanek 13 年之前 and when I use instead of <dependency> <groupId>portlet-api</groupId> <artifactId>portlet-api</artifactId> <version>1.0</version> <scope>provided</scope> </dependency>the <dependency> <groupId>javax.portlet</groupId> <artifactId>portlet-api</artifactId> <version>2.0</version> </dependency>Liferay crashes. 请登录以投票。 以……回复 取消
Madhura Raut 13 年之前 I am trying the below code to download PDF, XLS and CSV file from portlet. I am able to download CSV file currently but whenever I download PDF or XLS file I get corruptesd data. The reason for this is that I am trying to download the file in render phase which supports only text/html files. To achieve downloading for PDF and XLS we need to get it done in response phase but I dont know how to achieve this.For that I implemented the serveResource(ResourceRequest req, ResourceResponse res) method and read call the req.getResourceId() method of the ResourceRequest and invoked my business logic (create PDF) and subsequently write it to the output stream.But still I am stuck with the same problem.Currently I am using JSF 2 on portlet. Can anyone help me with the solution? public void DownloadPDF() throws DocumentException, FileNotFoundException, Exception { PortletResponse portletResponse = (PortletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); HttpServletResponse response= com.liferay.portal.util.PortalUtil.getHttpServletResponse(portletResponse); //We must get first our context FacesContext context = FacesContext.getCurrentInstance(); //Then we have to get the Response where to write our file //Now we create some variables we will use for writting the file to the response String filePath = null; int read = 0; byte[] bytes = new byte[1024]; String pathToTheFile="D:/NetbeansProject"; //Be sure to retrieve the absolute path to the file with the required method filePath = pathToTheFile; //Now set the content type for our response, be sure to use the best suitable content type depending on your file //the content type presented here is ok for, lets say, text files and others (like CSVs, PDFs) response.setContentType("application/pdf"); //This is another important attribute for the header of the response //Here fileName, is a String with the name that you will suggest as a name to save as //I use the same name as it is stored in the file system of the server. String fileName="tablePDF.pdf"; response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); //Streams we will use to read, write the file bytes to our response FileInputStream fis = null; OutputStream os = null; //First we load the file in our InputStream try { fis = new FileInputStream(new File(filePath,fileName)); os = response.getOutputStream(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //While there are still bytes in the file, read them and write them to our OutputStream try { while((read = fis.read(bytes)) != -1){ os.write(bytes,0,read); } os.flush(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Clean resources //This option isn't quite necessary, It worked for me with or without it FacesContext.getCurrentInstance().responseComplete(); //End of the method } 请登录以投票。 以……回复 取消
Ravi Bhaj 11 年之前 Hi All, How to download a file from portlet using a standalone java class? I was trying this by creating a simple portlet with serveResourse() method. The serveResource() would fetch the file. A standalone java class to hit this resourseURL to download a file. But I am not sure how to hit the resourseURL from a standalone java class.Please let me know if my approach is correct or suggest if there is any better approach.Thanks,Ravi 请登录以投票。 以……回复 取消
Praveen Mistry 6 年之前 Hi RAY AUGÉ,I`m not able to download File, in "Action Class" but it works for "serveResource" Method. Issue is to create "HttpServletResponse" object. I have posted my issue on following thread: https://web.liferay.com/community/forums/-/message_boards/message/93422404 请登录以投票。 以……回复 取消