2011-06-06 1 views
1

Salutations,Première page JSP - Utilisation de la matrice 2D - La page ne se remplit pas

Je tente d'écrire ma première page Java Bean + JSP à partir de zéro. Cependant, j'utilise un tableau 2D qui est rempli avec des valeurs arbitraires, et je suis maintenant faire une exception quand je lance la JSP disant que la propriété de tableau ne peut pas être trouvé:

JSP Exception: javax.el.PropertyNotFoundException: Property 'utilTableVals' not found on type diskUtil.tester 

Voici mon code de haricot :

package diskUtil; 

import java.text.DateFormat; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.Calendar; 
import java.util.Date; 
import java.util.*; 
import java.lang.*; 
import java.io.*; 


public class tester{ 

//public String [][] utilTableVals; 

String [][] utilTableVals = new String[20][20]; 

/*** 
bean's properties accessor 
***/ 

/*public String[][] getUtilTableVals() { 
       return utilTableVals; 
     }*/ 


public static String[][] getUtilTableVals()throws Exception{ 

tester du1 = new tester(); 
//String [][] utilTableVals = new String[20][20]; 

int i=0; 
int j=0; 

int row=0; 
int col=0; 
int result=0; 


for(int r = 0; r < du1.utilTableVals.length; r++) 
{ 
    for(int c = 0 ; c < du1.utilTableVals[r].length; c++) 
    { 
     result = r+c; 
      du1.utilTableVals[r][c]=Integer.toString(result); 
     //System.out.print(" " + utilTableVals[r][c]); 
    } 
} 

return du1.utilTableVals; 

}//end getUtilTableVals 

code Ma JSP est ici:

<%@ page contentType="text/html" %> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<hmtl> 
<head> 
<title>Disk Utilization Page</title> 
</head> 
<body> 
<h1>DISK UTILZATION REPORT</h1> 
<br> 

<jsp:useBean id="diskUtilData" scope="request" class="diskUtil.tester" /> 

<table> 
<c:forEach var="celldata" items="${diskUtilData.utilTableVals}"> 
     <tr> 
     <c:forEach var="col" items="${celldata}"> 
       <td> 
       <c:out value="${col}" /> 
       ${col} 
       <p>hello</p> 
       </td> 
     </c:forEach> 
</c:forEach> 
     </tr> 


</table> 
</body> 
</html> 

quelqu'un pourrait-il s'il vous plaît jeter un oeil? Merci d'avance.

-TU

Répondre

0

La méthode statique getUtilTableVals() du type Tester ne doit être accessible que de manière statique. Seules les méthodes non statiques obtiennent un appel dans votre expression EL.

+0

Merci à tous. Je l'ai eu le travail! –

0

La méthode de lecture doit être public et nonstatic. Vous devriez également faire le remplissage dans le constructeur ou la méthode d'action du bean, pas dans le getter.

public class Tester { // Classnames ought to start with uppercase. 

    private String[][] utilTableVals; // Properties ought to be private. 

    public Tester() { 
     utilTableVals = new String[20][20]; 
     // ... Preparing ought to be done in the constructor. 
    } 

    public String[][] getUtilTableVals() { // Getter ought to be public and non-static. 
     return utilTableVals; // Getter should do nothing more than just returning property. 
    } 

} 

Enfin, je recommande fortement d'utiliser une collection de Javabeans au lieu d'un tableau 2D. Voir aussi Places where JavaBeans are used? Ceci est beaucoup plus clair, efficace et auto-documentant que l'utilisation de tableaux simples.

0

Rend getUtilTableVals() non statique. <jsp:useBean> crée une instance de tester. Lorsque vous le référencez dans une expression EL, il appelle une méthode non statique.

Questions connexes