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



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

找不到 bean:"学生列表"在任何范围内

可能是什么问题?

File 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");
}
}

提交学生名单.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 + "]";
}
}

尝试在您的struts-config.xml 文件中限定(请求或会话(studentList bean 的范围。

最新更新