Thanks, Unfortunately that did not work either. Let me know if you figure out something.
Thanks
Main Topics
Browse All TopicsFollowing is the code that I have:
String file = "Acorn.xls";
response.reset();
response.setContentType("a
response.setHeader("Conten
This ends up opening a blank excel spreadsheet and not the one that I have store in the path. Can someone help me. I am not a servlet guy. Is there any easy way to accomplish this.
Thanks in advance.
Srini
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is the calling jsp
<tr>
<td>
<iframe src="RR.jsp" width="400" height="400" />>
</iframe></td>
</tr>
RR.jsp looks like this
<html>
<%@ page language="java" contentType="text/html;cha
<head>
<%@ page import = "java.sql.*,
com.rage.xim.commons.dal.D
com.rage.xim.commons.dal.D
java.util.ArrayList,
com.rage.xim.commons.cache
com.rage.xim.commons.admin
java.util.Map,
java.math.BigDecimal"%>
<%@ page import = "java.text.DateFormat" %>
<%@ page import = "com.jamonapi.*" %>
<%
String fileName = "Acorn.xls";
//response.reset();
response.setContentType("a
response.setHeader("Conten
%>
</head>
</html>
Thanks for trying to help me
Srini
Use the following for RR.jsp and is there any errors or exception in the logs?? Is the file Acorn.jsp is in the same folder where RR.jsp is ?
<html>
<%@ page language="java" contentType="application/v
<head>
<%@ page import = "java.sql.*,
com.rage.xim.commons.dal.D
com.rage.xim.commons.dal.D
java.util.ArrayList,
com.rage.xim.commons.cache
com.rage.xim.commons.admin
java.util.Map,
java.math.BigDecimal"%>
<%@ page import = "java.text.DateFormat" %>
<%@ page import = "com.jamonapi.*" %>
<%
String fileName = "Acorn.xls";
//response.reset();
response.setContentType("a
response.setHeader("Conten
%>
</head>
</html>
The reason you are getting a blank document is because you are not writing any data.
The line:
response.setContentType("a
Tells the brower what type of content to expect, i.e. an excel document.
This line:
response.setHeader("Conten
Tells the browser what the file name should be.
At no stage is the actuall content sent. Once these above steps have been executed, you wil then have to start writing data to the browser using out.println("") - this is the data that forms the exel document.
You would be far better doing this in a sevlet b(as opposed to a JSP). Set the headres first and only then start writging content to the browser. I dont think the code youve got above will compile, does it?
colr__
My apologies, you can in fact do this in a JSP. Here is what I have used befre. The content for the file comes from a database, but you can get this from elswhere depending on how your application works.
**************************
<%@page contentType="application/v
<%@page pageEncoding="UTF-8"%>
<%@page import="javax.sql.*, java.sql.*" %>
<%!
private java.sql.Connection getDBCon() throws javax.naming.NamingExcepti
javax.naming.Context c = new javax.naming.InitialContex
return ((javax.sql.DataSource) c.lookup("java:yourDS")).g
}
%>
<%
response.setHeader("conten
//''''''''''''''''''''''''
//''''''''''''''''''''''''
//''''''''''''''''''''''''
Connection con = getDBCon();
String strSQL = "SELECT * FROM yourtable";
PreparedStatement stmt = con.prepareStatement(strSQ
ResultSet rs = stmt.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
rs.last();
int size = rs.getRow();
rs.first();
//''''''''''''''''''''''''
//''''''''''''''''''''''''
//''''''''''''''''''''''''
//''''''''''''''''''''''''
out.write("<html><head></h
if (size > 0){
out.println("<table cellpadding=1 cellspacing=0 border=1><tr>");
for (int i=1; i<rsmd.getColumnCount()+1;
out.println("<td><font size=2><b>" + rsmd.getColumnName(i) + "</b></font></td>");
out.println("</tr>");
for (int i=0; i<size; i++){
out.println("<tr>");
for (int j=1; j<rsmd.getColumnCount()+1;
out.println("<td><font size=2>");
if (!rs.getString(j).equals("
out.println(rs.getString(j
else
out.println(" ");
out.println("</font></td>"
}
out.println("</tr>");
rs.next();
}
out.println("</table>");
}
out.println("</body></html
stmt.close(); rs.close(); con.close();
%>
**************************
To write an excel sheet, use parts of the code above, like the following:
<%@page contentType="application/v
<%@page pageEncoding="UTF-8"%>
<%@page import="javax.sql.*, java.sql.*" %>
<%
response.setHeader("conten
//''''''''''''''''''''''''
//''''''''''''''''''''''''
//''''''''''''''''''''''''
out.write("<html><head></h
// output the content of the ecel sheet using html tables.
ou.println("<table><tr><td
out.println("</body></html
%>
This code should actually work, so if you put this in a JSP and call it, you should get an excel sheet open up with the content filled in. You should be able to adapt this to your own content quite easily f you already have a referance to it in your code.
colr__
This should help:
http://jakarta.apache.org/
The above solutions work but not to the extent I wanted. Alternatively, what I did is as follows:
I started an inline frame and opened up the Excel in that iframe. The code is as follows:
<iframe src="file://c:/<%=filename
and this helped me open up an existing excel in a JSP page.
Guys thanks for you help. and for the help, I recommend the split as Colr recommends
Thanks
Business Accounts
Answer for Membership
by: fargoPosted on 2006-04-19 at 00:05:11ID: 16484966
there is nothing like response.reset();
pplication /vnd.ms-ex cel"); t-Disposit ion","atta chment; filename=\"" + fileName + "\";");
try the following and do make sure that the file Acorn.xls exists.
response.setContentType("a
response.setHeader("Conten