gpt4 book ai didi

java - Session 对象中的 ArrayList 似乎丢失了内容

转载 作者:行者123 更新时间:2023-12-02 00:00:47 24 4
gpt4 key购买 nike

我在从 session 中检索和转换 ArrayList 时遇到问题。我收到以下错误:

    javax.servlet.ServletException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

我将 arrayList 存储在 session 中:

    List<UserApplication> userList = uaDAO.searchUser(eds);
if (!userList.isEmpty()) {
request.getSession().setAttribute("userList", userList);
action_forward = EDITSUCCESS;

为了将 session 对象转换为 ArrayList,执行以下操作:

    EditStudentForm edt = (EditStudentForm)form;
if ((session.getAttribute("userList")) instanceof List){
List <UserApplication> studtList = (ArrayList<UserApplication>)session.getAttribute("userList");
}
try {
uaDAO.editUser(edt,studtList);
action_forward = EDITSUCCESS;
}

我在 DAO 类中遇到错误:

    public void editUser(EditStudentForm edt,List studtList) throws Exception {
PreparedStatement pst = null;
StringBuilder sb = new StringBuilder();
int stCode =Integer.parseInt(studtList.get(1).toString()); GETTING ERROR HERE
if (edt.getTitle() != null && !edt.getTitle().equals(studtList.get(2).toString())) {
sb.append("title = '").append(edt.getTitle()).append("'");
}
.
.

最佳答案

您明确要求列表中的第二个 (studtList.get(1)) 和第三个 (studtList.get(2)) 项目,但从未真正确定这个 list 足够大了。此外,您的代码显然甚至无法编译:

if ((session.getAttribute("userList")) instanceof List){
List <UserApplication> studtList = ///...
}
try {
uaDAO.editUser(edt,studtList);

studtListtry block 中无法访问,if 语句中的括号也不匹配。

关于java - Session 对象中的 ArrayList 似乎丢失了内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14901195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com