JSP usebean中的异常

时间:2009-11-23 06:29:08

标签: java exception jsp usebean

我一直在使用JSP usebean,当我尝试在JSP中使用bean时,它抛出一个异常“它找不到类”。但我认为,我遵循了正确的结构,并包含了所需的一切。请仔细阅读代码,让我知道可能是什么问题。

//init.jsp
--------
<%@ page import="com.wipro.upload.extract.EmployeeDetailsExtract" %>
<%@ page import="com.wipro.upload.extract.ColumnDetailsExtract" %>
<%@ page import="com.wipro.upload.extract.dto.Employee" %>
<%@ page import="com.wipro.upload.bean.Data" %>
<jsp:useBean id="detailsbean" class="com.wipro.upload.bean.Data" scope="session" />
<jsp:setProperty name="detailsbean" property="*" />
<%
 detailsbean.setValues(new EmployeeDetailsExtract("c:\\new.xls").employeeListExtracter());
 List list=detailsbean.getValues();

 Iterator itr=list.iterator();
 while(itr.hasNext())
 {
  Employee emp=(Employee)itr.next();
  out.println(emp.employeeName);
 }
%>

// Data.java
package com.wipro.upload.bean;
import java.util.*;
public class Data
{
 private List column;
 private List values;
 public Data()
 {
 }
 public void setColumn(List column)
 {
  this.column=column;
 }

 public List getColumn()
 {
  return column;
 }
 public void setValues(List values)
 {
  this.values=values;
 }
 public List getValues(List values)
 {
  return values;
 }
}

尝试执行上述代码时出错

org.apache.jasper.JasperException: /init.jsp(6,0) The value for the useBean class attribute com.wipro.upload.bean.Data is invalid.
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1272)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3426)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:216)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

1 个答案:

答案 0 :(得分:4)

您无法将*List一起使用。 jsp引擎正在尝试将转换请求值(String)转换为目标属性的类型。 有关<jsp:setProperty />的信息,请Check this。你的bean中必须只有原语(及其包装器)+ String - int(Integer),long(Long)等。