JSP usebean 中的异常

发布于 2024-08-11 16:49:51 字数 2941 浏览 10 评论 0原文

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

I've been working with JSP usebean, when I am trying to use bean in JSP, its throwing an exception that "It cannot find the class". But I've followed the correct structure, I assume, and included everything required. Please go through the code and let me know what could be the problem.

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

The error occuring while trying to execute the above code is,

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耳钉梦 2024-08-18 16:49:51

您不能将 *List 一起使用。 jsp 引擎正在尝试将请求值(字符串)转换为目标属性的类型。
检查此以获取有关 >.你的 bean 中必须只有基元(及其包装器)+字符串 - int (Integer)、long (Long) 等。

You can't use * with List. The jsp engine is trying convert request values (which are String) to the type of the target property.
Check this for information about <jsp:setProperty />. You must have only primitives (and their wrappers)+String in your bean - int (Integer), long (Long), etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文