急,高手救命!getOutputStream() Exception (第二次发帖) 把 <html><head><title>enabling entry fields</title></head>等信息去掉就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 现在奇怪的是,这样都不行!<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*,java.io.OutputStream,java.io.File,java.io.FileOutputStream" errorPage="" %><jsp:useBean id="Excel" scope="session" class="college.Excel"/><jsp:useBean id="EditCon" scope="session" class="college.Contracts"/><% response.reset(); response.setContentType("application/vnd.ms-excel"); Excel.nqhmc(response.getOutputStream());%>………………………………………Excel.nqhmc(OutputStream os)……………………………… public boolean nqhmc(OutputStream os){ ResultSet rsSql = null; boolean bResult = false; Connection myConn = this.getdbConn(); try{ jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os); jxl.write.WritableSheet ws = wwb.createSheet("人员花名册",0); String sSql = "SELECT * FROM table WHERE ((ID='') or (ID is null))"; Statement stSql = myConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rsSql = stSql.executeQuery(sSql); //获取记录总数 rsSql.last(); int intRowCount = rsSql.getRow(); ResultSetMetaData rmeta = rsSql.getMetaData(); //获得数据字段个数 int numColumns = rmeta.getColumnCount(); for(int i=1; i<intRowCount; i++){ for(int j=0; j+1<numColumns; j++){ String str = rsSql.getString(j+1); jxl.write.WritableCell label = new Label(j,i,str); ws.addCell(label); rsSql.next(); } } wwb.write(); wwb.close(); bResult = true; }catch(Exception e){ this.dbException = e.toString(); bResult = false; } return bResult; } 把 <jsp:useBean id="Excel" scope="session" class="college.Excel"/><jsp:useBean id="EditCon" scope="session" class="college.Contracts"/>去掉看看下面的<%@ page contentType="text/html; charset=GBK" %><%@ page import = "java.io.*"%><%@ page import = "com.elink.hr.bean.*"%><%@ page import = "com.elink.database.*"%><% // from www.elingke.com String downtype = request.getParameter("downtype"); String downid = request.getParameter("downid"); DocumentBean docs = new DocumentBean(); CachedRowSet crs = docs.getDocument( downid ); if( crs!=null && crs.next() ) { String docuri = crs.getString( "docuri" ); String filename = docuri; int p1 = filename.lastIndexOf("."); String file_name = filename.substring(p1); filename = filename.substring(0,p1); p1 = filename.lastIndexOf(File.separator); filename = filename.substring(p1); p1 = filename.indexOf("."); int p2 = filename.indexOf(".", p1+1); file_name = filename.substring(p1+1, p2)+file_name; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition","attachment; filename=" + java.net.URLEncoder.encode(file_name, "UTF-8") ); try { FileInputStream stream = new FileInputStream(docuri); OutputStream sout = response.getOutputStream(); int iRead = stream.read(); while ( iRead != -1) { sout.write( iRead ); iRead = stream.read(); } sout.flush(); } catch( Exception e ) { e.printStackTrace(); } } else { response.sendRedirect( "error.bo?errno=90104" ); }%> 这里把我弄晕了:filename = filename.substring(0,p1); p1 = filename.lastIndexOf(File.separator); filename = filename.substring(p1); p1 = filename.indexOf("."); int p2 = filename.indexOf(".", p1+1); file_name = filename.substring(p1+1, p2)+file_name;这里又是什么意思:response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition","attachment; filename=" + java.net.URLEncoder.encode(file_name, "UTF-8") );小弟刚学jsp,还请netcom19(netcom)兄不吝赐教! JAVA群收人,喜欢JAVA的人进。。。 参数传递问题 jsp页面设计问题 关于Spring中代理类的问题 插入数据库图片问题 这条语句为什么不能更新数据库? struts 下拉列表问题 计算机本科,java,6月底毕业,找工作 jquery ui checkbox的样式问题 关于表单提交的问题 急 我在安装Tomacat之前,测试http://localhost:8080/就出现“该页无法显示”,怎么办? jsp 定位 下拉列表
<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*,java.io.OutputStream,java.io.File,java.io.FileOutputStream" errorPage="" %>
<jsp:useBean id="Excel" scope="session" class="college.Excel"/>
<jsp:useBean id="EditCon" scope="session" class="college.Contracts"/>
<%
response.reset();
response.setContentType("application/vnd.ms-excel");
Excel.nqhmc(response.getOutputStream());
%>
………………………………………Excel.nqhmc(OutputStream os)………………………………
public boolean nqhmc(OutputStream os){
ResultSet rsSql = null;
boolean bResult = false;
Connection myConn = this.getdbConn();
try{
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);
jxl.write.WritableSheet ws = wwb.createSheet("人员花名册",0);
String sSql = "SELECT * FROM table WHERE ((ID='') or (ID is null))";
Statement stSql = myConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rsSql = stSql.executeQuery(sSql);
//获取记录总数
rsSql.last();
int intRowCount = rsSql.getRow();
ResultSetMetaData rmeta = rsSql.getMetaData();
//获得数据字段个数
int numColumns = rmeta.getColumnCount();
for(int i=1; i<intRowCount; i++){ for(int j=0; j+1<numColumns; j++){
String str = rsSql.getString(j+1);
jxl.write.WritableCell label = new Label(j,i,str);
ws.addCell(label);
rsSql.next();
} }
wwb.write();
wwb.close();
bResult = true;
}catch(Exception e){
this.dbException = e.toString();
bResult = false;
}
return bResult;
}
<jsp:useBean id="Excel" scope="session" class="college.Excel"/>
<jsp:useBean id="EditCon" scope="session" class="college.Contracts"/>
去掉
看看下面的<%@ page contentType="text/html; charset=GBK" %>
<%@ page import = "java.io.*"%>
<%@ page import = "com.elink.hr.bean.*"%>
<%@ page import = "com.elink.database.*"%>
<%
// from www.elingke.com
String downtype = request.getParameter("downtype");
String downid = request.getParameter("downid");
DocumentBean docs = new DocumentBean();
CachedRowSet crs = docs.getDocument( downid );
if( crs!=null && crs.next() )
{
String docuri = crs.getString( "docuri" );
String filename = docuri;
int p1 = filename.lastIndexOf(".");
String file_name = filename.substring(p1);
filename = filename.substring(0,p1);
p1 = filename.lastIndexOf(File.separator);
filename = filename.substring(p1);
p1 = filename.indexOf(".");
int p2 = filename.indexOf(".", p1+1);
file_name = filename.substring(p1+1, p2)+file_name; response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment; filename=" + java.net.URLEncoder.encode(file_name, "UTF-8") );
try
{
FileInputStream stream = new FileInputStream(docuri);
OutputStream sout = response.getOutputStream();
int iRead = stream.read();
while ( iRead != -1)
{
sout.write( iRead );
iRead = stream.read();
}
sout.flush();
}
catch( Exception e )
{
e.printStackTrace();
}
}
else
{
response.sendRedirect( "error.bo?errno=90104" );
}
%>
filename = filename.substring(0,p1);
p1 = filename.lastIndexOf(File.separator);
filename = filename.substring(p1);
p1 = filename.indexOf(".");
int p2 = filename.indexOf(".", p1+1);
file_name = filename.substring(p1+1, p2)+file_name;
这里又是什么意思:
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment; filename=" + java.net.URLEncoder.encode(file_name, "UTF-8") );
小弟刚学jsp,还请netcom19(netcom)兄不吝赐教!