Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

jsp + servlet +jxl ʵÏÖ export excel

 Ð´Ò»¸öjspÎļþ,È»ºó°ÑÒª´ÓÊý¾Ý¿âÈ¡³öÊý¾ÝµÄsqlÓï¾ä´«µ½servlet ÖÐ.
java ´úÂë:
package exportExcel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class exportExcel extends HttpServlet{
 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  try {
   
  String sqlStr  = (String) req.getParameter("exSql").toLowerCase();
  String sqlS = sqlStr.split("from")[0];
  String sqls = sqlS.split("select")[1];
  //System.out.println(sqls);
  String[] Sql;
  List list = new ArrayList();
  String excelName = req.getParameter("exName");                                     
  HttpSession session = req.getSession();
  String jdbc_driver=(String) session.getAttribute("jdbc_driver");
  String jdbc_url = (String) session.getAttribute("jdbc_url");
  String jdbc_username= (String)session.getAttribut


Ïà¹ØÎĵµ£º

JSPÖÐʹÓÃJavaBean

<jsp:useBean>¶¯×÷ÓÃÓÚʵÀý»¯JavaBean£¬»òÕ߶¨Î»Ò»¸öÒѾ­´æÔÚµÄJavaBeanʵÀý£¬²¢°ÑʵÀýµÄÒýÓø³¸øÒ»¸ö±äÁ¿¡£
Óï·¨ÈçÏ£º
<jsp:useBean id="cart" scope="session" class="org.sunxin.lesson.jsp.bookstore.CartBean">
<jsp:setProperty>¶¯×÷ºÍ<jsp:useBean>Ò»ÆðʹÓã¬ÓÃÀ´ÉèÖÃJavaBeanµÄ¼òµ¥ÊôÐ ......

jsp Çåcookie

<%@ page contentType="text/html; charset=GBK" language="java"%>
<%
String[] cookiename = {"JSESSIONID","SECURE_AUTH_ROOT_COOKIE","SECURITY_AUTHENTICATION_COOKIE"};
for(int index = 0, len = cookiename.length; index < len; index ++) {
javax.servlet.http.Cookie c = new javax.s ......

Jsp ELÓï·¨

Jsp ELÓï·¨
Àý£º
${sessionScope.user.sex}
ËùÓÐEL¶¼ÊÇÒÔ ${ ΪÆðʼ¡¢ÒÔ} Ϊ½áβµÄ¡£
ÉÏÊöEL·¶ÀýµÄÒâ˼ÊÇ£º´ÓSessionÈ¡µÃÓû§µÄÐÔ±ð¡£Èç¹ûʹÓÃ֮ǰJSP´úÂëµÄд·¨ÈçÏ£º
<%
User user = (User)session.getAttribute(”user”);
String sex = user.getSex( );
%>
Á½ÕßÏà±È½Ï֮ϣ¬¿ÉÒÔ·¢ÏÖELµÄÓï·¨± ......

JSPÒ³ÃæµÄ´íÎó´¦Àí

 Æä´úÂëÈçÏÂ:
<%@page language="java" contentType="text/html"  import="java.util.*"  %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<html>
  <body>
  <%
int a=9;
int b=0;
try{
%>
<%=(a/b)%>
<%
}cat ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ