• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to save a file in client machine

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI All,

I have write a web enabled page to convert jsp to excel file using with POI,and successful to do that.

My problem is that when user acess that web page at client computer the file is save at server instead of client machine.

I want to save the file at their machine.

Please help me...I'm failed to solve it.

Following is my code.

<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFPrintSetup"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>

...............................
...............................


<% PreparedStatement ps=null;
Connection con=null;
ResultSet rs=null;
int i=0;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@172.16.90.139:1531:PROD","apps","apps");
String f_date=request.getParameter("f_date");
String t_date=request.getParameter("t_date");

ps=con.prepareStatement("SELECT PV.VENDOR_NAME VNAME,FV.DESCRIPTION STATE,to_char(AIA.GL_DATE,'dd-mon-yyyy') GL_DATE,to_char(AIA.INVOICE_DATE,'dd-mon-yyyy') INV_DATE,AIA.INVOICE_NUM INV_NUM,AID.DISTRIBUTION_LINE_NUMBER LINE_NO,AID.AMOUNT AMOUNT, "+
"SUM(ROUND((NVL(AID.AMOUNT,0)*NVL((JIT.TAX_RATE),0)*0.01),0)) WCT FROM AP_INVOICE_DISTRIBUTIONS_ALL AID,AP_INVOICES_ALL AIA, "+
"JA_IN_TAX_CODES JIT,PO_VENDORS PV,FND_FLEX_VALUES_VL FV,GL_CODE_COMBINATIONS GLCC WHERE AIA.INVOICE_ID=AID.INVOICE_ID "+
"AND AIA.ACCTS_PAY_CODE_COMBINATION_ID=GLCC.CODE_COMBINATION_ID AND GLCC.SEGMENT3=FV.FLEX_VALUE AND FV.FLEX_VALUE_SET_ID='1009606' "+
"AND AID.ATTRIBUTE_CATEGORY='India Distributions' AND AID.ATTRIBUTE2 IS NOT NULL AND AID.ATTRIBUTE2=JIT.TAX_ID AND PV.VENDOR_ID=AIA.VENDOR_ID "+
"AND AIA.GL_DATE >=? AND AIA.GL_DATE <=? "+
"GROUP BY PV.VENDOR_NAME,FV.DESCRIPTION,AID.DISTRIBUTION_LINE_NUMBER,AID.AMOUNT,AIA.GL_DATE, "+
"AIA.INVOICE_DATE,AIA.INVOICE_NUM ORDER BY AIA.GL_DATE,AIA.INVOICE_NUM ");

ps.setString(1,f_date);
ps.setString(2,t_date);
rs=ps.executeQuery();


HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFSheet sheet1 = hwb.createSheet("second sheet");
HSSFRow rows = sheet.createRow((short)0);
HSSFCell cells = rows.createCell((short)0); cells.setCellValue("Vendor Name:");
...................

.....................
while(rs.next())


try{
i++;
{

HSSFRow row = sheet.createRow((short)0+i);
HSSFCell cell = row.createCell((short)0); cell.setCellValue(rs.getString(1));
HSSFCell cell1 = row.createCell((short)1); cell1.setCellValue(rs.getString(2));

}


FileOutputStream fileOut = new FileOutputStream("c:\\excel\\wct.xls");

hwb.write(fileOut);
fileOut.close();


}



catch ( Exception ex )
{
}
out.println("Your excel file has been generated,please see C drive:");


%>
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to put the file in the HttpServletResponse and set the correct MIME-type. For some security reasons it's entirely up to the client to download the file or not.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you sloved the problem.

You get the ServletOutputStream object and flush the file in to the outputstream. this will work.
 
Subhradip Podder
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Anshul Malpani,

Can you write me some code about this problem. Because i've limit knowledge about servlet.


Please help me.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the SimpleStream example in the CodeBarn. It shows how to stream binary files to the client from a servlet. (You will need to do this in a servlet, because JSPs can't handle binary responses.)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic