this is a very important question where i got struck...it will be highly appreciable if anyone can answer it!!
Error message:
Feb 19, 2014 6:56:08 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.bdisys.promorphics.domain.Blog
at org.apache.jsp.Mydetails_jsp._jspService(Mydetails_jsp.java:951)
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:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Details of blogs are===[[Ljava.lang.Object;@18fc85, [Ljava.lang.Object;@6a86fe, [Ljava.lang.Object;@1c49309, [Ljava.lang.Object;@9160e3, [Ljava.lang.Object;@6fecea, [Ljava.lang.Object;@2b0e77, [Ljava.lang.Object;@c2c269, [Ljava.lang.Object;@699ec3, [Ljava.lang.Object;@363c6c, [Ljava.lang.Object;@b9141c, [Ljava.lang.Object;@d75341, [Ljava.lang.Object;@9af4bc, [Ljava.lang.Object;@1399537, [Ljava.lang.Object;@173640c, [Ljava.lang.Object;@ad799a, [Ljava.lang.Object;@10aa63a, [Ljava.lang.Object;@274a2b, [Ljava.lang.Object;@1767836, [Ljava.lang.Object;@ce5230, [Ljava.lang.Object;@175fbe3]
DaoImpl Method:
this is my Dao method where i am executing sql query and returning the list of objects to my jsp page for printing it.
public List<Blog> getTopBlogsQuesByDate()throws Exception {
List<Blog> blogs = new ArrayList<Blog>(0);
try{
String sql = "select title , date from (select blog_title as title ,created_date as date from blog union select ask_question as title , created_on as date from askquestions ) as aa order by date desc";
SQLQuery query = getSession().createSQLQuery(sql);
return query.list();
}
catch(Exception e){
e.printStackTrace();
}finally{
closeSession();
}
return blogs;
}
Jsp:
Here am getting data of two tables using sql query but how should i print the list of values in my jsp?????it is showing classcast exception?????it would be highly appreciable if any one can answer it!!thanks in advance.....
<tr>
<td style="border: 2px dotted #FFFFFF; border-radius:5px; background-color:#f3ecf0;">
<%
List<Blog> blog2 =new ArrayList<Blog>();
BlogDaoImpl blogDaoImpl1=new BlogDaoImpl();
blog2=blogDaoImpl1.getTopBlogsQuesByDate();
System.out.println(" Details of blogs are==="+blog2);
%>
<ul style="text-align: left; left:0px;font-size: 13px; margin-left:-20px; overflow-y: scroll; height:465px; list-style:url('images/arrows.png'); font-family:Palatino Linotype; color:#2a2a2a; border: 0px solid #d4d4d4" >
<%
for(int i=0;i<blog2.size();i++){
Blog blogs1=new Blog();
blogs1=blog2.get(i);
System.out.println("blogs size is===="+blog2.size());
blogs1.getId();
String paths="showblog/"+ blogs1.getBlogTitle()+"/"+blogs1.getId();
%>
<li style="border-bottom : 2px dotted #FFFFFF; margin-bottom: 10px;"><%=blogs1.getBlogText() %></li>
<%} %>
</ul>
</td>
</tr>
return
statements in yourgetTopBlogsQuesByDate
method, one of which (the first) probably shouldn't be there. You likely want to iterate through your results, creating instances ofBlog
and adding them to theblogs
method variable, then finally returning that at the end of the method. – Anthony Grist Feb 19 at 13:42