java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(ArrayList.java:547)
java.util.ArrayList.get(ArrayList.java:322)
cn.com.jobedu.blog.GetBlogServlet.doGet(GetBlogServlet.java:42)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)其中GetBlogServlet.java的代码是:
package cn.com.jobedu.blog;import java.io.IOException;
import java.sql.SQLException;
import java.util.List;import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;public class GetBlogListServlet extends HttpServlet {
private static final long serialVersionUID = -7152478870507997462L; public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 数据源对象可以理解为连接池的管理者,通过他可以获取数据库的连接
DataSource ds = null;
try {
// 通过在context.xml文件,设定的数据源对象的名字,获取数据源对象
Context context = new InitialContext();
ds = (DataSource) context.lookup("java:/comp/env/jdbc/mysqlds");
} catch (Exception e) {
System.out.println("获取数据源时出错");
}

try {
// 添加博文的SQL语句,now()生成当前系统时间
String sql = "select id,title,content,createdtime from blog orde by id";
// DButils中核心类,生成对象时传递数据源对象
QueryRunner qr = new QueryRunner(ds);
List list=(List)qr.query(sql,new BeanListHandler(Blog.class));
request.setAttribute("List", list);
request.getRequestDispatcher("/displayBlogList.jsp").forward(request,
response);
} catch (SQLException e) {
e.printStackTrace();
}
}
}