强烈求助~~

bing100 2010-03-05 09:01:27
用的是 MyEclipse tomcat 和 mysql
提交了servlet
返回的页面显示说
type Exception report

message

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.

求助各位高人怎么改呀
...全文
76 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
huhk 2010-03-06
  • 打赏
  • 举报
回复
好像是数组中没有元素,但是你却去访问。要先判断数组的length。
huhk 2010-03-06
  • 打赏
  • 举报
回复
数组越界,应该是超出范围了。
phoenix_qiqi 2010-03-05
  • 打赏
  • 举报
回复

cn.com.liuna.family.GetBlogServlet.doGet(GetBlogServlet.java:46)
wxzyydy 2010-03-05
  • 打赏
  • 举报
回复
这个提示还像是说数组下标越界,你检查一下得到的集合是不是空的,我之前也遇到过类似的问题
bing100 2010-03-05
  • 打赏
  • 举报
回复
import java.io.IOException;
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);
}
}
//}

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧