2017-08-22 10 views
1

私はStruts 1フレームワークを使用してCSVをサーバーにアップロードし、データベース(Mysql)に保存しています。しかし、データベースからデータを取得してJSPに表示すると、エラーが返されます。Beanを見つけることができません: "studentList"(スコープ内)

Cannot find bean: “studentList” in any scope

何が問題になりますか?

ファイル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> 

ファイルUploadForm:

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; 
// 
//}} 

ファイルStudentList:

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

ファイル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 + "]"; 
    } 
} 
+0

これは推測ですが、 "request.setAttribute(" st "、studentList);" 「st」の代わりに「studentList」を持つべきでしょう。 – AHungerArtist

+0

はい。私は自分の投稿を編集していた。しかしエラーです:( – namtuocdn

+0

はstudentListですか? – user7294900

答えて

0

あなたのstruts-config.xmlファイル内のスコープ(リクエストまたはセッション)studentList Beanに試してみてください。

+0

私は設定があったが動作していない:( – namtuocdn

関連する問題