on 11-30-2006 12:50 PM
hi,
i need to download files from server context root to client side using servlet !!!
is it possible ????
regards
Guru
Hi,
Its possible to download files to client side. Copy the files to your servlet context and provide them as Hyper Link.
Regards
Abhilash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
i hava done as said .but it is not working ...
error is:requested resource does not exists.
i have typed url like : http://192.168.1.76:50000/download/xxx pgf
can u pls tell how to use servlet inputstree and out put stree to read and write files
regards
Guru
Hi Guru,
Here is the solution, check the code. This code can be used for word, excel,ppt, pdf file types. If you need any other files then add them in if condtions.
Add the following code into your service or doPost or doGet method. Here you need not to keep the files under web context folder. You can keep folders any where in the system and you can refer it.
////////////////////
String fileName = "test.pdf";
String filePath = "g:
";
String fileType = fileName.substring(fileName.lastIndexOf("."),fileName.length());
response.setHeader("Content-Disposition","attachment; filename="+fileName);
if (fileType.trim().equalsIgnoreCase("doc"))
{
response.setContentType( "application/msword" );
}
else if (fileType.trim().equalsIgnoreCase("xls"))
{
response.setContentType( "application/vnd.ms-excel" );
}
else if (fileType.trim().equalsIgnoreCase("pdf"))
{
response.setContentType( "application/pdf" );
}
else if (fileType.trim().equalsIgnoreCase("ppt"))
{
response.setContentType( "application/ppt" );
}
else
{
response.setContentType( "application/octet-stream" );
}
FileInputStream fis = new FileInputStream(filePath+fileName);
byte in[] = new byte[512];
response.setContentLength(fis.available());
OutputStream stream = response.getOutputStream();
while(fis.read(in)>0)
stream.write(in);
stream.flush();
stream.close();
///////////////
Regards
Abhilash
hi
pls check code once
//String fileName = (String) request.getParameter("file");
String fileName = "\one.doc";
String filePath = "D:\usr\sap\J2E\JC00\j2ee\cluster\server0";
String fileType = fileName.substring(fileName.lastIndexOf("."),fileName.length());
regards
Guru
response.setHeader("Content-Disposition","attachment; filename="+fileName);
if (fileType.trim().equalsIgnoreCase("doc"))
{
response.setContentType( "application/msword" );
}
else if (fileType.trim().equalsIgnoreCase("xls"))
{
response.setContentType( "application/vnd.ms-excel" );
}
else if (fileType.trim().equalsIgnoreCase("pdf"))
{
response.setContentType( "application/pdf" );
}
else if (fileType.trim().equalsIgnoreCase("ppt"))
{
response.setContentType( "application/ppt" );
}
else if (fileType.trim().equalsIgnoreCase("jar"))
{
response.setContentType( "application/jar" );
}
else if (fileType.trim().equalsIgnoreCase("cbc"))
{
response.setContentType( "application/cbc" );
}
else
{
response.setContentType( "application/octet-stream" );
}
FileInputStream fis = new FileInputStream(filePath+fileName);
byte in[] = new byte[512];
response.setContentLength(fis.available());
OutputStream stream = response.getOutputStream();
while(fis.read(in)>0)
stream.write(in);
stream.flush();
stream.close();
}
}
Guru,
If you want to directly open the XML file you can place that file under context root or remove the content disposition and header information from previous code. If you want to achieve all things in a single servlet then based on the file type set the header and content disposition.
Generally system default path will be Temp files. If you want to find the path you can use java.io.File class.
Regards
Abhilash
hi,
Abhilash
just i have seen ur previous posts about sales order ..
i have some doubts , can u explain?
<b>in BAPI_SALESORDER_CREATEFROMDAT2</b>
1.i set the doc_type is "TA" in headerin
2.i set the part_role is "AG" in partner
3.i setupdate flag is "I" in headerinx.............................X,X,X...??
<b>my doubt is wht are the meaning to TA,AG,I ...etc and how to know the meanings??</b>
regards
Guru
hi,
up
up
up
servlet is working fine. but the problem is , it is displaying content in browser when i call this servlet url from<b> mobile browser</b>. where as it is working fine wheni call servlet url from system.
mobile is WIN C. is there any setting i need to do in mobile.
regards
Guru
Message was edited by:
Guruvulu Bojja
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.