public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/vnd.ms-excel"); String par = request.getParameter("acct_month"); HttpSession session = request.getSession(); String prod_unit_name = (String) session.getAttribute("username"); if (session.getAttribute("username").equals("Administrator")) { String sql = "select acct_month,prod_unit_name,device_number,innet_date,net_type,channel_name,town_name,innet_channel_no,dealer_name,city_desc,lac_city_desc,all_fee,all_income,max_userlable from zomto_jzjf_mingxi where acct_month='" + par + "'";
try { getExcelResult excel = new getExcelResult(); //downloadExcel excel = new downloadExcel(); excel.getExcelResult(sql, response.getOutputStream());//这儿提示错误 } catch (WriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { String sql = "select acct_month,prod_unit_name,device_number,innet_date,net_type,channel_name,town_name,innet_channel_no,dealer_name,city_desc,lac_city_desc,all_fee,all_income,max_userlable from zomto_jzjf_mingxi where acct_month='" + par + "'and prod_unit_name='" + prod_unit_name + "'";
//downloadExcel excel = new downloadExcel(); getExcelResult excel = new getExcelResult(); excel.getExcel(sql, response.getOutputStream()); } }
/** * Initialization of the servlet. <br> * * @throws ServletException * if an error occurs */ public void init() throws ServletException { // Put your code here }
发布评论
评论(3)
String sql = "select acct_month,prod_unit_name,device_number,innet_date,net_type,channel_name,town_name,innet_channel_no,dealer_name,city_desc,lac_city_desc,all_fee,all_income,max_userlable 是这个。User怎么写?已晕。。
在servlet里面提示错误:
public class downloadExcelServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public downloadExcelServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
String par = request.getParameter("acct_month");
HttpSession session = request.getSession();
String prod_unit_name = (String) session.getAttribute("username");
if (session.getAttribute("username").equals("Administrator")) {
String sql = "select acct_month,prod_unit_name,device_number,innet_date,net_type,channel_name,town_name,innet_channel_no,dealer_name,city_desc,lac_city_desc,all_fee,all_income,max_userlable from zomto_jzjf_mingxi where acct_month='"
+ par + "'";
try {
getExcelResult excel = new getExcelResult();
//downloadExcel excel = new downloadExcel();
excel.getExcelResult(sql, response.getOutputStream());//这儿提示错误 } catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
String sql = "select acct_month,prod_unit_name,device_number,innet_date,net_type,channel_name,town_name,innet_channel_no,dealer_name,city_desc,lac_city_desc,all_fee,all_income,max_userlable from zomto_jzjf_mingxi where acct_month='"
+ par + "'and prod_unit_name='" + prod_unit_name + "'";
//downloadExcel excel = new downloadExcel();
getExcelResult excel = new getExcelResult();
excel.getExcel(sql, response.getOutputStream());
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
你写了可能是数据量太大,不知道你总共是多少条数据使用Jxl写入到Excel中,如果是office2000的excel的写入的记录是有限制的,当最大行是Integer的最大值时就会报错。
另外你说不能分Sheet导是指什么意思,你的代码直接是和数据库关连我也没办法去运行