用的是 MyEclipse tomcat 和 mysql
提交了servlet
返回的页面显示说
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(Unknown Source)
java.util.ArrayList.get(Unknown Source)
cn.com.liuna.family.GetBlogServlet.doGet(GetBlogServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.还有MyEclipse里显示
严重: A web application created a ThreadLocal with key of type [null] (value [com.sun.faces.config.ConfigureListener$1@e5ace9]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.求助各位高人怎么改呀
提交了servlet
返回的页面显示说
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(Unknown Source)
java.util.ArrayList.get(Unknown Source)
cn.com.liuna.family.GetBlogServlet.doGet(GetBlogServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.还有MyEclipse里显示
严重: A web application created a ThreadLocal with key of type [null] (value [com.sun.faces.config.ConfigureListener$1@e5ace9]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.求助各位高人怎么改呀
import java.sql.SQLException;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;public class BlogServlet extends HttpServlet {
private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 解决从JSP页面接受中文参数乱码
request.setCharacterEncoding("UTF-8"); // HttpSession session = request.getSession();
/* User user = (User) session.getAttribute("user");
if (user == null) {
response.sendRedirect("/blogResult.jsp");
} else {
*/
// 接受JSP页面传递过来的,与博文有关的3个参数:主题、内容和所属分类的编号
String title = request.getParameter("title");
String content = request.getParameter("content");
String categoryId = request.getParameter("category");
String limits = request.getParameter("limits"); // 数据源对象可以理解为连接池的管理者,通过他可以获取数据库的连接
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("获取数据源时出错");
}
int result = 0; try {
// 添加博文的SQL语句,now()生成当前系统时间
String sql = "insert into blog (title,content,category_id,limits,created_time) values (?,?,?,?,now())";
// 为SQzhegL语句中的?设定参数
String params[] = { title, content, categoryId,limits};
// DButils中核心类,生成对象时传递数据源对象
QueryRunner qr = new QueryRunner(ds);
// 调用它的update,完成SQL的运行。其他使用update方法的SQL语句:insert
// into/update/delete
result = qr.update(sql, params); // query()
} catch (SQLException e) {
e.printStackTrace();
} String message = "";
if (result == 1) {
message = "添加博文成功!";
} else {
message = "添加博文失败!";
} request.setAttribute("message", message);
request.getRequestDispatcher("/blogResult.jsp").forward(request,
response);
}
}
//}
cn.com.liuna.family.GetBlogServlet.doGet(GetBlogServlet.java:46)