| Author |
File download using a servlet: Problems with the generated URL
|
|
|
| Hello, fellows.
I'm trying to implement a file download functionality in an IBM Struts Portlet. I've read several posts on the subject and I decided to go to the servlet option. However, I've not found any tested and reliable code that does that and I've not even success
fully generate the URL to the servlet. It's been 3 days and no luck!
This is my progress so far:
I was able to add the servlet to my portlet project. Code fragment in the Web.xml:
<web-app id="WebApp">
...
<servlet id="Servlet_2">
<servlet-name>FileDownloadServlet</servlet-name>
<display-name>FileDownloadServlet</display-name>
<servlet-class>com.gedas.omegaq.docmgr.servlet.FileDownloadServlet</servlet-class>
</servlet>
...
<servlet-mapping>
<servlet-name>FileDownloadServlet</servlet-name>
<url-pattern>/FileDownloadServlet</url-pattern>
</servlet-mapping>
Note: The webapp is the same that contains the WpsStrutsPortlet.
And in my JSP I coded the following:
<html:link page='<%=response.encodeURL("FileDownloadServlet")%>'>A File</html:link>
The generated URL stills contains portlet context and therefore it doesn't reach the servlet:
http://localhost:9081/wps/myportal/!ut/p/_s.7_0_A/7_0_16IE/.cmd/ad/.ar/sa.spf_ActionListener/.c/6_0_16FA/.ce/7_0_16IG/.p/5_0_16C5/.d/2?PC_7_0_16IG_spf_strutsAction=%212f. OMQ_PSA_Definition%212fFileDownloadServl
et#7_0_16IG
I've read in a topic that the request and response objects should not be the portlet ones but I've not found any reference on how to do that.
Any help or reference will be enormously appreciated.
Best regards!
| |
|
| I am using render response to do this in my portlet. I think this should also
work in the JSP.
String url = response.encodeURL( request.getContextPath() +
"/Servlet");
Thanks,
Mohan
| |
|
| Hello, Mohan.
I decided to implement the servlet in a separate WAR project and to call it directly using the HTML anchor tag as following:
<a href="/FileDownload/FileDownloadServlet">Something</a>
That finally worked. Thanks anyway!
Cheerz,
Azbel.
| |
|
| Hey Azbel,
From where does the fileDownloadServlet take the file to download? Can you post the code-snippet for
1. invoking that servlet (from Portlet Jsp) and
2. downloading the file and sending it to the user (servlet code)
It will be great help indeed.
Thanx in advance..
|
|
|
|