views:

294

answers:

1

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)
+4  A: 

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.

Bozho
shall i use like this<jsp:setproperty name="" property="values" />values is an attribute in Data.java...
i2ijeya
you can't set Lists with jsp:setPropety. If you have checkboxes or multiple selects in your page, use String[] or int[].
Bozho
In my application the employe objects are stored on the list and the details should be stored into the database. So what kind of property can i use to attain my need?
i2ijeya
well, this bean should represent a single user. You can later add it to the list and persist it in a database.
Bozho