此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【helloruby】截止到2008-07-23 16:09:36的历史汇总数据(不包括此帖):
发帖的总数量:17 发帖的总分数:440 每贴平均分数:25
回帖的总数量:9 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:16 结贴的总分数:407
无满意结贴数:2 无满意结贴分:23
未结的帖子数:1 未结的总分数:33
结贴的百分比:94.12 % 结分的百分比:92.50 %
无满意结贴率:12.50 % 无满意结分率:5.65 %
值得尊敬
楼主【helloruby】截止到2008-07-23 16:09:36的历史汇总数据(不包括此帖):
发帖的总数量:17 发帖的总分数:440 每贴平均分数:25
回帖的总数量:9 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:16 结贴的总分数:407
无满意结贴数:2 无满意结贴分:23
未结的帖子数:1 未结的总分数:33
结贴的百分比:94.12 % 结分的百分比:92.50 %
无满意结贴率:12.50 % 无满意结分率:5.65 %
值得尊敬
JFileChooser fileChooser = new JFileChooser("F:\\");
fileChooser.setDialogTitle("Select File to Save");
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
String file = fileChooser.getSelectedFile();
}
file就是得到的绝对路径了
下载:java 代码public class DownLoadAction extends Action {
// --------------------------------------------------------- Instance
// Variables
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
// --------------------------------------------------------- Methods
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String downloadPath = servlet.getInitParameter("file-upload");
String fileName = new String(request.getParameter("filename").getBytes(
"ISO-8859-1"), "GB2312");
response.reset();
response.setContentType("application/x-msdownload");
response.addHeader("Content-Disposition", "attachment; filename=\""
+ new String(fileName.getBytes("GB2312"), "ISO-8859-1") + "\"");
try {
bis = new BufferedInputStream(new FileInputStream(downloadPath
+ "/" + fileName));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[20480];
while ((bis.read(buff, 0, buff.length)) != -1) {
bos.write(buff, 0, buff.length);
}
bos.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
bos.close();
bis.close();
}
return mapping.findForward("downloadfile");
}
}struts-configxml 代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="uploadForm" type="com.capinfo.form.upload.UploadForm" />
</form-beans>
<global-forwards>
<forward name="welcome" path="/Welcome.do" />
<forward name="login" contextRelative="true" path="/login/Login.do" redirect="true" />
<forward name="upload" path="/page/upload.jsp" redirect="true"/>
</global-forwards>
<action-mappings>
<action path="/Welcome" type="org.apache.struts.actions.ForwardAction" parameter="/page/Welcome.jsp"></action>
<action path="/upload" type="com.capinfo.action.upload.UploadAction" name="uploadForm" input="/page/upload.jsp" scope="request">
<forward name="success" path="/page/upload.jsp" />
</action>
<action path="/downLoad"
type="com.yourcompany.struts.action.DownLoadAction"
input="/page/upload.jsp"
scope="request"
>
<forward name="downloadfile" path="/page/upload.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
<html>
<head>
<title> New Document </title>
</head>
<body>
<input type="file" id="file" style="display:none">
<input type="button" value="click" onClick="ok()">
</body>
<script language="JavaScript">
<!-- function ok(){
var s = document.getElementById("file");
s.click();
var str = s.value;
alert(str);
}
//-->
</script>
</html>
import java.io.OutputStream;
import java.util.List;import jxl.Workbook;
import jxl.write.WritableFont;
public class ExcelBean {
public String expordExcel(List list,OutputStream os )throws Exception
{
jxl.write.WritableWorkbook wbook=Workbook.createWorkbook(os);//建立Excel文件
String title="测试数据";
jxl.write.WritableSheet sheet=wbook.createSheet("第一页", 0);//为文件的sheet设置名字
//设置标题 start
jxl.write.WritableFont wfont=new jxl.write.WritableFont(WritableFont.ARIAL,16,WritableFont.BOLD,false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK); //设置标题的格式
jxl.write.WritableCellFormat wcformat=new jxl.write.WritableCellFormat(wfont);
jxl.write.Label wlabel;
wlabel=new jxl.write.Label(1,0,title,wcformat);//把标题放到excel文件中‘2’代表列,‘0’代表行,title是内容,wcformat是格式
sheet.addCell(wlabel);
//设置标题 end
//设置表头 start
wfont=new jxl.write.WritableFont(WritableFont.ARIAL,14,WritableFont.BOLD,false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.DARK_GREEN); //设置表头的格式
wcformat=new jxl.write.WritableCellFormat(wfont);
wlabel=new jxl.write.Label(0,1,"TID",wcformat);
sheet.addCell(wlabel);
wlabel=new jxl.write.Label(2,1,"Tname",wcformat);
sheet.addCell(wlabel);
//设置表头 end
//输出数据格式的设置 start
wfont=new jxl.write.WritableFont(WritableFont.ARIAL,14,WritableFont.BOLD,false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK); //设置表头的格式
wcformat=new jxl.write.WritableCellFormat(wfont);
for(int i=0;i<list.size();i++)
{
TestForm tf=(TestForm)list.get(i);
wlabel=new jxl.write.Label(0,i+2,tf.getTid(),wcformat);
sheet.addCell(wlabel);
wlabel=new jxl.write.Label(2,i+2,tf.getTname(),wcformat);
sheet.addCell(wlabel);
}
wbook.write();
wbook.close();
//输出数据格式的设置 end
return "success";
}}
import java.io.OutputStream;
import java.util.List;import jxl.Workbook;
import jxl.write.WritableFont;
public class ExcelBean {
public String expordExcel(List list,OutputStream os )throws Exception
{
jxl.write.WritableWorkbook wbook=Workbook.createWorkbook(os);//建立Excel文件
String title="测试数据";
jxl.write.WritableSheet sheet=wbook.createSheet("第一页", 0);//为文件的sheet设置名字
//设置标题 start
jxl.write.WritableFont wfont=new jxl.write.WritableFont(WritableFont.ARIAL,16,WritableFont.BOLD,false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK); //设置标题的格式
jxl.write.WritableCellFormat wcformat=new jxl.write.WritableCellFormat(wfont);
jxl.write.Label wlabel;
wlabel=new jxl.write.Label(1,0,title,wcformat);//把标题放到excel文件中‘2’代表列,‘0’代表行,title是内容,wcformat是格式
sheet.addCell(wlabel);
//设置标题 end
//设置表头 start
wfont=new jxl.write.WritableFont(WritableFont.ARIAL,14,WritableFont.BOLD,false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.DARK_GREEN); //设置表头的格式
wcformat=new jxl.write.WritableCellFormat(wfont);
wlabel=new jxl.write.Label(0,1,"TID",wcformat);
sheet.addCell(wlabel);
wlabel=new jxl.write.Label(2,1,"Tname",wcformat);
sheet.addCell(wlabel);
//设置表头 end
//输出数据格式的设置 start
wfont=new jxl.write.WritableFont(WritableFont.ARIAL,14,WritableFont.BOLD,false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK); //设置表头的格式
wcformat=new jxl.write.WritableCellFormat(wfont);
for(int i=0;i<list.size();i++)
{
TestForm tf=(TestForm)list.get(i);
wlabel=new jxl.write.Label(0,i+2,tf.getTid(),wcformat);
sheet.addCell(wlabel);
wlabel=new jxl.write.Label(2,i+2,tf.getTname(),wcformat);
sheet.addCell(wlabel);
}
wbook.write();
wbook.close();
//输出数据格式的设置 end
return "success";
}}
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.struts.action;import java.io.OutputStream;
import java.util.List;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.business.TestBusiness;
import com.struts.form.ExcelBean;
/**
* MyEclipse Struts
* Creation date: 03-20-2008
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class TestDownloadAction extends Action {
/*
* Generated Methods
*/ /**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String filename="mytest";//文件名称
TestBusiness tb=new TestBusiness();
List list=tb.getData();//导出的数据集合
try {
OutputStream os=response.getOutputStream();//获取输出流
response.reset();
response.setHeader("Content-disposition", "attachment; filename=" + filename + ".xls");//设定输出文件头
response.setContentType("application/msexcel");//设定输出类型
ExcelBean eb=new ExcelBean();
eb.expordExcel(list, os);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("success");
}
}
<%@ page language="java" pageEncoding="UTF-8"%><%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />
<title>Download.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<html:form action="/testDownload">
<html:submit value="daochu"></html:submit>
</html:form>
</body>
</html:html>