Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Elliott Jones   on Jun 29 In Java Category.

  
Question Answered By: Skye Hughes   on Jun 29

I am sending the code what i had used for downloading the file from the
server.we will be using the hastable and store the downloable data.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import ServletUtils;
import java.util.*;

public class down extends HttpServlet {

String str="";
public void init(ServletConfig config) throws ServletException{
super.init(config);
}

public void download(String myfilename,String filename,HttpServletResponse
res,HttpServletRequest req)
throws ServletException, IOException{
HttpSession session = req.getSession(true);
String strUserId = (String)(session.getValue("userid"));
String strBrowser = new String("");
String strDomain = (String)(session.getValue("userdomain"));
String strSetting = (String)(session.getValue("usersetting"));

if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE") == -1)
strBrowser="NN";
else
strBrowser="IE";
if(strBrowser.equals("NN"))
{
res.setContentType("application/octet-stream; name="+filename+"");
res.setHeader("Content-Disposition","attachment; filename=\"" + filename +
"\";");
}

else if(strBrowser.equals("IE"))
{ res.setContentType("application/x-filler");
res.setHeader("Content-Disposition","attachment; filename=\"" + filename +
"\";");
}

System.out.println("filename isn download  is "+filename);
ServletOutputStream out=res.getOutputStream();
try{
ServletUtils.returnFile(myfilename,out);

}
catch(FileNotFoundException fnfe){System.out.println("fileNot
Found+_+_+>"+fnfe);}
out.flush();
out.close();
}
public String downloadAmtFormat(String strAmt)
{
String Amount="";
if((strAmt==null) || (strAmt.equals("")))
Amount="\t";
else
{
StringTokenizer st=new StringTokenizer(strAmt,",");
while(st.hasMoreElements())
Amount+=st.nextElement();
Amount+="\t";
}
return Amount;
}
}

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on How to download a page from a web server? Or get search suggestion and latest updates.


Tagged: