I am having download option in my jsp like this
<a href='<c:url value="/licensing/download.sp?name=${namelist.name}&downloadUrl=${namelist.url}"/>'>
<img src="/images/download.gif" alt="Download" border="0" align="right">
In the above "url" is the location of file and name is the file name.On click of download option in jsp iam calling the controller method download,in controller
public ModelAndView download(HttpServletRequest request, HttpServletResponse response, DevTechBean devTechBean) throws Exception {
cat.debug("MySuiteListController: download: begin");
ModelAndView modelView = super.handleLicensingRequest(request, response);
String name = request.getParameter("name");
String url1 = request.getParameter("downloadUrl");
cat.debug(" download: url ="+url1);
String downloadurl1="https://my.net:8869"+url1;
cat.debug(" download: downloadurl ="+downloadurl1);
try{
URL url = new URL(downloadurl1);
//response.setHeader("Content-Type", "text/csv");
response.setHeader("Content-disposition", "attachment;filename="+name);
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream());
int len;
byte[] buf = new byte[1024];
while ((len = stream.read(buf)) > 0) {
outs.write(buf, 0, len);
}
outs.close();
}
catch (MalformedURLException e) {
cat.error("Error occurrred in url");
}
catch (IOException e) {
cat.error("Error occurrred ");
}
String viewName = "swl_download";
modelView.setViewName(viewName);
return modelView;
}
But when i click on download i am getting file not found exception. Iam thinking that problem is due to the url value. In the above iam having value of downloadurl=/files/download/hai.txt
when i give
<a href="${namelist.url}"/>
<img src="/images/download.gif" alt="Download" border="0" align="right"></a><br/><br/></td>
on click the file is opening in browser with the url https://my.net:8869//files/download/hai.txt(but here for href iam giving only this link "/files/download/hai.txt" dont know how the entire link is coming.
but if give link like this to call the controller for opening that file as pop up.
<a href='<c:url value="/download.sp?name=${namelist.name}&downloadUrl=${namelist.url}"/>'>
it is getting file not found exception. I think it is due that do downloadUrl.so i have added like this in above
String downloadurl1="https://my.net:8869"+url1;
But i am getting file not find exception.Please help me resolving this.