gpt4 book ai didi

java - JSP usebean 中的异常

转载 作者:行者123 更新时间:2023-12-01 19:24:53 25 4
gpt4 key购买 nike

我一直在使用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)

最佳答案

您不能使用*List 。 jsp 引擎正在尝试将请求值(字符串)转换为目标属性的类型。 Check this有关<jsp:setProperty />的信息。你的 bean 中必须只有基元(及其包装器)+字符串 - int (Integer)、long (Long) 等。

关于java - JSP usebean 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1781432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com