Java 找不到bean:“;学生名单&x201D;在任何范围内

Java 找不到bean:“;学生名单&x201D;在任何范围内,java,Java,我使用Struts1框架将CSV上传到服务器并保存在数据库(Mysql)中。但当我从数据库获取数据并在JSP中显示时,它会抛出一个错误: 在任何范围内都找不到bean:“studentList” 问题是什么 文件struts config.xml。 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Strut

我使用Struts1框架将CSV上传到服务器并保存在数据库(Mysql)中。但当我从数据库获取数据并在JSP中显示时,它会抛出一个错误:

在任何范围内都找不到bean:“studentList”

问题是什么

文件struts config.xml。

 <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts 
    Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
    <struts-config>
        <form-beans>
            <form-bean name="fileUploadForm" type="form.FileUploadForm">
            </form-bean>        
        </form-beans>

        <action-mappings>
            <action input="/input.jsp" path="/upload" name="fileUploadForm"
                attribute="fileUploadForm" type="action.FileUploadAction" scope="request">
                <forward name="success" path="/pages/studentList.jsp" />
            </action>

            <action input="/studentList.jsp" path="/listStudentPage"
                type="action.StudentListPageAction" name="studentList">
                <forward name="success" path="/pages/studentList.jsp" />
            </action>
            <action path="/listStudentPage" parameter="/pages/studentList.jsp" type="action.StudentListPageAction" /> 
        </action-mappings>

        <message-resources parameter="action.ApplicationResources" />
    </struts-config>
文件学生列表:

package form;

import javax.servlet.ServletRequest;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;

public class FileUploadForm extends ActionForm{


    private FormFile file;

    public FormFile getFile() {
        return file;
    }

    public void setFile(FormFile file) {
        this.file = file;
    }
}
//  @Override
//  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
//       ActionErrors errors = new ActionErrors();
//          if (file.getFileSize() == 0) {
//              errors.add("file", new ActionMessage("error.file.required"));
//          } else if (!file.getContentType().equals("application/csv")) {
//              errors.add("file", new ActionMessage("error.file.type"));
//          }
//        //logs debug
//          if(logger.isDebugEnabled()){
//              logger.debug("WelcomeAction.execute()");
//          }
//
//          //logs exception
//          logger.error("This is Error message", new Exception("Testing"));
//
//          return mapping.findForward("success");
//          /**
//          * If the file size is greater than 20kb.
//          */
//          else if (file.getFileSize() > 20480) {
//              errors.add("file", new ActionMessage("error.file.size"));
//          }
//          return errors;
//  
//}}
package action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import bean.Student;
import dao.StudentDAO;
import pagination.Pages;

public class StudentListPageAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        StudentDAO studentDAO = new StudentDAO();       
        List<Student> studentList = new ArrayList<>();

        //get page current. if param is empty, set current is 1
        String selPage = (String) request.getParameter("selPage");
        if("".equals(selPage) || selPage == null){
            selPage = "1";
        }

        //get all list actor
        studentList = studentDAO.getallUser();

        //set paging for list actor
        if (studentList != null && !studentList.isEmpty()) {
            Pages page = new Pages();
            page.setTotalSize(studentList.size());
            page.setCurrPage(Integer.parseInt(selPage));
            int min = page.minIndex();
            int max = 0;
            max = page.maxIndex(studentList.size());
            request.setAttribute("studentList",studentList.subList(min, max));
            request.setAttribute("page", page);
        }
        return mapping.findForward("success");
    }
}

尝试在struts-config.xml文件中定义(请求或会话)studentList bean。

尝试在struts-config.xml文件中定义(请求或会话)studentList bean。

这是一个猜测,但“request.setAttribute(“st”,studentList);”可能应该是“studentList”而不是“st”。是的。我已经编辑了我的帖子。但是它的错误是:(studentList为空吗?不。我认为它不是空的。当我在jsp中使用命令时,它显示数据。这是一个猜测,但“request.setAttribute(“st”,studentList)”;“也许应该用”studentList“代替”st。是的。我编辑了我的帖子。但是它的错误是:(studentList为空吗?不。我认为它不是空的。当我在jsp中使用命令时,它显示数据。
 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>This is all information</title>
</head>
<body>
<table class="table table-hover">
    <tr>
        <th>UserID</th>
        <th>firstName</th>
        <th>lastName</th>
        <th>email</th>
        <th>password</th>
        <th></th>
    </tr>
    <logic:iterate name="studentList" id="studentListId">
        <tr>
            <td><bean:write name="studentListId" property="userId" /></td>
            <td><bean:write name="studentListId" property="fistName" /></td>
            <td><bean:write name="studentListId" property="lastName" /></td>
            <td><bean:write name="studentListId" property="email" /></td>
            <td><bean:write name="studentListId" property="password" /></td>

        </tr>
    </logic:iterate>
</table>
package bean;

public class Student {
    private String userId;
    private String firstName;
    private String lastName;
    private String email;
    private String password;
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @Override
    public String toString() {
        return "Student [userId=" + userId + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email
            + ", password=" + password + "]";
    }
}