Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing file to server

Status
Not open for further replies.

Ciarrai

Technical User
Jun 27, 2003
17
US
Hi,
i am trying to empty the contents of an excel file into an excel spreadsheet - i'm using HSSF. It works fine when i'm testing it on tomcat on my local machine, but when I try to write to a folder on the web server it doesn't appear. The file path is absolute and I set the folder permissions to 777. Can anyone offer some ideas? Much obilged.


protected void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
doPost(req,res);
}


protected void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try{
stmt = con.createStatement();
queryString15 = ("SELECT * from lastweeksheet ORDER BY date ASC");
rs2 = stmt.executeQuery(queryString15);
String results [][] = new String[3][2];

rs2.next();
for (int i=0;i<3;i++)
{
for (int j=0;j<2;j=j+1)
{
System.out.println("Nice!");
results[j] = rs2.getString(1);
j++;
results[j] = rs2.getString(2);
System.out.println("Done!");
}
rs2.next();
}
for (int i=0;i<3;i++)
{

for (int j=0;j<2;j=j+1)
{
day = results[j];
j++;
format = results[j];
queryString14 = ("SELECT * from "+day+" ORDER BY time ASC");
rs1 = stmt.executeQuery(queryString14);
// create a new workbook
HSSFWorkbook wb = new HSSFWorkbook();
// create a new sheet
HSSFSheet s = wb.createSheet();
// declare a row object reference
HSSFRow r = null;
// declare a cell object reference
HSSFCell c = null;

// set the sheet name in Unicode
wb.setSheetName(0,"Timesheet");
//System.out.println(rs2.getString(1));

int rownum = 0;

while (rs1.next())
{
//create a row
r = s.createRow(rownum);
r.setHeight( (short) 0x200 );
rownum++;
if ( format.equals("Fourball"))
{
for (short cellnum = (short) 0; cellnum < 5; cellnum ++)
{ //String cellValue;

c = r.createCell((short) (cellnum));
c.setCellType(HSSFCell.CELL_TYPE_STRING);
c.setCellValue(rs1.getString(cellnum+1));
s.setColumnWidth((short)(cellnum),(short) 5000);

}
}
else
{
for (short cellnum = (short) 0; cellnum < 4; cellnum ++)
{ //String cellValue;

c = r.createCell((short) (cellnum));
c.setCellType(HSSFCell.CELL_TYPE_STRING);
c.setCellValue(rs1.getString(cellnum+1));
s.setColumnWidth((short)(cellnum),(short) 5000);
System.out.println(rs1.getString(cellnum+1));
}
}
}//end while rs1
System.out.println("READY TO WRITE FILE");

FileOutputStream fileOut = new FileOutputStream("/**start of absolute address hidden*//public_html/files/"+day+".xls");
wb.write(fileOut);
fileOut.close();

//day = rs2.getString(1);
//format = rs2.getString(2);
}//end inner for
}//end for

}//end try
catch (SQLException e){System.out.println("Error: "+e);}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top