leeson1125
asked on
How to associate local file system with the path setting in WAR file.
I am using JBoss as my web server(on Win 2K) and have a web application( using Struts) in war file.
In my application, the client need to download some PDF files on server. These PDF files were created by another applcation(Jasper) and stored in server file system. I want to have a link on page point to the file, but I could not find a way to associate local file system with the path configuration in WAR file.
I searched forum, there are some topics about absolute path in WAR,
https://www.experts-exchange.com/questions/21004006/Absolute-application-path.html
but I guess mine problem should be easier.
Can anyone give me some hint about this?
Thanks in advance!
In my application, the client need to download some PDF files on server. These PDF files were created by another applcation(Jasper) and stored in server file system. I want to have a link on page point to the file, but I could not find a way to associate local file system with the path configuration in WAR file.
I searched forum, there are some topics about absolute path in WAR,
https://www.experts-exchange.com/questions/21004006/Absolute-application-path.html
but I guess mine problem should be easier.
Can anyone give me some hint about this?
Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ahhh,
I thought that you are implementing without db. Well, now as i understand you, u want to use relative path instead of absolute path for your files with respect to your web application path.
Is that right???
I thought that you are implementing without db. Well, now as i understand you, u want to use relative path instead of absolute path for your files with respect to your web application path.
Is that right???
ASKER
No, I have DB and most of my implementation is similiar to your suggestion.
my servlet:
public void doPost(HttpServletRequest request,
HttpServletResponse response){
WebApplicationContext ctx
= WebApplicationContextUtils .getWebApp licationCo ntext(
request.getSession().getSe rvletConte xt());
//I am using Spring framework.
Report report = (Report)ctx.getBean("repor t");
String reportKey = request.getParameter("repo rtId");
OutputStream outStream = response.getOutputStream() ;
String filePath = report.getReportPathByHash Key(report Key);
File file = new File(filePath);
FileInputStream fin = new FileInputStream(file);
response.setContentType("a pplication /pdf");
//response.setContentType( "applicati on/OCTET-S TREAM");
//response.setHeader("Cont ent-Dispos ition", "filename=\"Report.pdf\"") ;
response.setHeader("Conten t-Disposit ion", "attachment; filename=\"Report.pdf\"");
//response.setHeader("Cont ent-Dispos ition", "filename=\"Report.pdf\"") ;
// response.setHeader("Cache- Control", "no-cache");
byte[] buf = new byte[1024];
int sizeRead = 0;
while ((sizeRead = fin.read(buf, 0, buf.length)) != -1){
outStream.write(buf, 0, sizeRead);
}
outStream.flush();
fin.close();
out.close();
}
The link on my JSP:
<a href="Download?reportId=32 4890" TARGET="_blank">Download </a>
When user click the link on jsp, it will popup a blank window and a download dialog asking user to choose"Open", "Save". If user click Open, then the popup window will close and the file will be opened by Acrobat reader, but if Save is clicked, after downloading finish, the popup window is still there.
Do you know how to close that popup window?
my servlet:
public void doPost(HttpServletRequest request,
HttpServletResponse response){
WebApplicationContext ctx
= WebApplicationContextUtils
request.getSession().getSe
//I am using Spring framework.
Report report = (Report)ctx.getBean("repor
String reportKey = request.getParameter("repo
OutputStream outStream = response.getOutputStream()
String filePath = report.getReportPathByHash
File file = new File(filePath);
FileInputStream fin = new FileInputStream(file);
response.setContentType("a
//response.setContentType(
//response.setHeader("Cont
response.setHeader("Conten
//response.setHeader("Cont
// response.setHeader("Cache-
byte[] buf = new byte[1024];
int sizeRead = 0;
while ((sizeRead = fin.read(buf, 0, buf.length)) != -1){
outStream.write(buf, 0, sizeRead);
}
outStream.flush();
fin.close();
out.close();
}
The link on my JSP:
<a href="Download?reportId=32
When user click the link on jsp, it will popup a blank window and a download dialog asking user to choose"Open", "Save". If user click Open, then the popup window will close and the file will be opened by Acrobat reader, but if Save is clicked, after downloading finish, the popup window is still there.
Do you know how to close that popup window?
Why are you using
>>TARGET="_blank"
Since your servlet puts the stream as attachment, the browser will itself throw the dialog of open/save. The above line opens a new window. Try removing it.
>>TARGET="_blank"
Since your servlet puts the stream as attachment, the browser will itself throw the dialog of open/save. The above line opens a new window. Try removing it.
ASKER
here is my implementation:
When system generated file, the absolute path will be store into database
On jsp page, using <a href="Download?reportId=32
URL pattern \Download will be mapped to DownLoadServlet where java io is used to "open that file and redirect the fileoutputstream to the out stream", but using absolute path of file.
It seems my implementation is different from your suggestion. I can't understand your "Now, you can use the [paths - (folderpath)] i.e. the realtive paths as the hyperlinks, and whenever a user clicks that hyperlink".
Could you give me more detailed information?
Thanks in advance. :-)