Tuesday, 14 May 2013

Upload and Download multiple files at a time using JSP-Servlet

Step 1:
Upload and Download multiple files at a time using JSP-Servlet.

for eg code

function displayTable(data)
{
   $("#Uploadfile table").remove();
if(data!="null"||data!="undefind")
{
    var objArray=JSON.parse(data);
    var count=1;                                      //  UserName,filename,filepath,FileID,Uplodated_Datetime                                                                                                                                          
var glacc="<center><table border='1'><tr align='center'><th></th><th>User Namer</th><th>file Name</th><th>File ID</th><th>Date Of uploading</th></tr>";
$.each(objArray, function(index,jsonObject){

glacc+="<tr align='center'><td id='uploadfile"+count+"' onclick='getid(this.id)'><a href='#'>download</a></td><td id='name"+count+"'>"+jsonObject.UserName+"</td><td id='filename"+count+"'>"+jsonObject.filename+"</td><td id='fileid"+count+"'>"+jsonObject.FileID+"</a></td><td>"+jsonObject.Uplodated_Datetime+"</td></tr>";
count=count+1;
});

 glacc+="</table></center>";
      $("#Uploadfile").append(glacc);
      $("#printPage").show();

}
}


function showfile(hid)
{
var id=hid.substring(4,hid.length);
var act=$("#activity"+id).text();

var complance=$("#complance"+id).text();
complance=complance.substring(0,10);

var name=$("#name"+id).text();

//alert("name="+name+"complance="+complance+"act="+act);
waiting_effect_on();
$.ajax({ type: "Post", url: "show_uploadfile",
data:{flag:1,Username:name,activity:act,c_date:complance},
cache:false,
success : function(data){
waiting_effect_off();
alert(data);
if(data=="]")
{
msg_box('No File Avilable','A',function(result){

});
}
else
{
$("#submitDIV2").show();
displayTable(data);
}

}
});

}











Step 2:

 click on Link to download file
  call this function 


function getid(id)
{

   $.ajax({ type: "Post", url: "downloadfile",
data:{filename:filename},
cache:false,
success : function(data){
window.location.href="tempdownloadfile.jsp?backurl="+window.location.href;

}
});

}


Step 3:
write code on Downloadfile.jsp


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<script type="text/javascript">


function whatFile()
{
alert("1");
var url='file:///' + 'C://Users/1100lt031/Desktop/2012-White-Jaguar-XKR-S-Convertible-3Q-Front-1152x2048.jpg';
alert(url);
window.open(url,'Download');
}

function startDownload()
{
   var url='http://localhost:8080/Project/Report/1368005388533/REC_ADVT_16_2013.pdf';
  /*  var url="file:///E:/Siddharth/Relese Statergy/Multi Level Purchase Order Release Strategy.pdf";
  alert(url); */
  window.open(url,'Download');

}
</script>


</head>
<body>
<input type="button" onclick="startDownload();"/>
<a href="download/VB6IP.zip">Download</a>
<a href="http://localhost:8080/Project/Multi Level Purchase Order Release Strategy.pdf">http://localhost:8080/Project/Multi Level Purchase Order Release Strategy.pdf</a>


</body>
</html>

Step 4:
Output:










No comments:

Post a Comment