0

i am trying to get the list from my dao class to it into my jsp page.

My list is returning fine from my DAO class but while iterating the return list into my jsp page i am unable to get the values of tables column

Please help me to solve this issue.

Error in console:

org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: java.lang.Integer cannot be cast to         
com.ebhasin.bstalentscareers.beans.Bsmostviewjp
    at org.apache.jsp.jsps.BSHomePage_jsp._jspService(BSHomePage_jsp.java:594)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    ------------
    ----------

DaoCLass.java

public List getpopularJobProvider()
  {
  List list = null;
  try
   {
     session=HibernateUtil.getSessionFactory().openSession();
     transaction=session.beginTransaction();
     ProjectionList pl=Projections.projectionList();
     pl.add(Projections.distinct(Projections.property("jobProviderId")));
     list=session.createCriteria(Bsmostviewjp.class).addOrder(Order.desc("counter")).setProjection(pl).setMaxResults(4).list();
     System.out.println("List  of the most popular job provider in dao-"+list.size());//this is fine
     transaction.commit();
   }
    catch (Exception e)
    {
         if(transaction!=null && transaction.isActive())
                {
                    try
                    {
                         transaction.rollback();
                    }
                    catch (Exception e1)
                    {
                         System.out.println("Exception in getpopularJobProvider Rollback  :" + e1);
                    }
                }
        System.out.println("Exception in getpopularJobProvider :"+e);
    }
    return list; 
}

jspPage.jsp

 <tr> 
     <%
     List mostpopjplist=jposting.getpopularJobProvider();
       Iterator mostit=mostpopjplist.iterator();
         while(mostit.hasNext())
         { 
          Bsmostviewjp bsmostviewjp=(Bsmostviewjp) mostit.next();//Problem here  
         Integer jpId=bsmostviewjp.getJobProviderId(); 
     %>
  <td>
    <%=jpId%> 
   </td>
       <%}%>
</tr>

Bsmostviewjp.java (Bean/pojo CLass)

import java.util.Date; 
public class Bsmostviewjp  implements java.io.Serializable {


     private Integer mvjpId;
     private int jobSeekerId;
     private int jobId;
     private int jobProviderId;
     private int counter;
     private Date appliedOn;

    public Bsmostviewjp() {
    }

    public Bsmostviewjp(int jobSeekerId, int jobId, int jobProviderId, int counter, Date appliedOn) {
       this.jobSeekerId = jobSeekerId;
       this.jobId = jobId;
       this.jobProviderId = jobProviderId;
       this.counter = counter;
       this.appliedOn = appliedOn;
    }

    public Integer getMvjpId() {
        return this.mvjpId;
    }

    public void setMvjpId(Integer mvjpId) {
        this.mvjpId = mvjpId;
    }
    public int getJobSeekerId() {
        return this.jobSeekerId;
    }

    public void setJobSeekerId(int jobSeekerId) {
        this.jobSeekerId = jobSeekerId;
    }
    public int getJobId() {
        return this.jobId;
    }

    public void setJobId(int jobId) {
        this.jobId = jobId;
    }
    public int getJobProviderId() {
        return this.jobProviderId;
    }

    public void setJobProviderId(int jobProviderId) {
        this.jobProviderId = jobProviderId;
    }
    public int getCounter() {
        return this.counter;
    }

    public void setCounter(int counter) {
        this.counter = counter;
    }
    public Date getAppliedOn() {
        return this.appliedOn;
    }

    public void setAppliedOn(Date appliedOn) {
        this.appliedOn = appliedOn;
    } 
}
Dan
  • 2,086
  • 11
  • 71
  • 137

3 Answers3

0

First of all, you should not use List and Iterator without parametize them. I mean you must indicate what type of elements you list contains. So instead of List, Iterator, you should write List<Integer>, Iterator<Integer> or List<Bsmostviewjp>. This will allow the compiler to tell you a lot more easily when something is wrong. see this very good explanation of why. This gives you type safety, which is incredibly useful.

After you've done this, I guess you will find the error very quickly.

Secondly, you should not use scriptlets in jsp, but use taglibs instead. See this.

autra
  • 895
  • 6
  • 21
0

Instead of

List list = null;

use

List< Bsmostviewjp > list = null;

code_fish
  • 3,381
  • 5
  • 47
  • 90
0

Integer bsmostviewjp=(Integer) mostit.next(); is my solution as suggested by Stefan Be

Dan
  • 2,086
  • 11
  • 71
  • 137