Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Type mismatch: cannot convert from Object to HashMap

Posted on 2006-11-07
10
Medium Priority
?
11,559 Views
Last Modified: 2011-08-18
Hi

I am trying to pass the ArrayList as a request to result.jsp using requestdispatcher.
I am getting syntax error as below

org.apache.jasper.JasperException: Exception in JSP: /update.jsp:46

43:  RequestDispatcher view =
44:  request.getRequestDispatcher("result.jsp");
45:  //--Use the request dispatche to ask the container to crank JSP
46:  view.forward(request, response);
47: %>
48: </body>
49: </html>


Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to List

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
it cannot be resolved

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to HashMap

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
length.calval cannot be resolved to a type

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to int

CODE

result.jsp

<%@ page language="java" import="java.sql.*" import="java.util.*" %>
<html>
<body>
<%
List  a1 = request.getAttribute("data");
Iterator listIt = a1.iterator ();
while (it.hasNext ()) {
    HashMap colval = listIt.next();
    int id;
    for(int i = 1; i <= length.calval; i++) {
    Integer key = new Integer(i);
      String iKey = key.toString();
      if(i == 1){
      id = colval.get(iKey);
      }
      else{
      %>
      <%= colval.get(iKey) %>
<%  
      }
 }
 %>
 <br>
 <%
}
%>
</body>
</html>
0
Comment
Question by:basirana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 10

Accepted Solution

by:
jaggernat earned 2000 total points
ID: 17892023
try this

List  a1 = (List)request.getAttribute("data");
0
 

Author Comment

by:basirana
ID: 17892135
Hi

Still I am getting below error can you please check once.

Exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to HashMap

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
length.colval cannot be resolved to a type

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to int

CODE

<%@ page language="java" import="java.sql.*" import="java.util.*" %>
<html>
<body>
<%
List rowval = (ArrayList)request.getAttribute("data");
Iterator listIt = rowval.iterator ();
while (listIt.hasNext ()) {
    HashMap colval = listIt.next();
    int id;
    for(int i = 1; i <= length.colval; i++) {
    Integer key = new Integer(i);
      String iKey = key.toString();
      if(i == 1){
      id = colval.get(iKey);
      }
      else{
      %>
      <%= colval.get(iKey) %>
<%  
      }
 }
 %>
 <br>
 <%
}
%>
</body>
</html>
0
 

Author Comment

by:basirana
ID: 17892199
I am doing something similar to below and trying to access in result.jsp

   /* create our list of maps  */
   ArrayList list = new ArrayList();
   Map map = new HashMap();
   map.put("name", "horse");
   map.put("price", "00.00");
   list.add( map );
 
   map = new HashMap();
   map.put("name", "dog");
   map.put("price", "9.99");
   list.add( map );
   map = new HashMap();
   map.put("name", "bear");
   map.put("price", ".99");
   list.add( map );
   
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:jaggernat
ID: 17892337
instead of   HashMap colval = listIt.next();


try this

HashMap colval = new HashMap();
colval = (HashMap)listIt.next();
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17892381
or  just

HashMap colval = colval = (HashMap)caseIterator.next();
0
 

Author Comment

by:basirana
ID: 17893122
Can you please check the error below

Error:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /result.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to int


      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jsp.update_jsp._jspService(update_jsp.java:96)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Code:

<%@ page language="java" import="java.sql.*" import="java.util.*" %>
<html>
<body>
<%
List rowval = (List)request.getAttribute("data");
Iterator listIt = rowval.iterator ();
while (listIt.hasNext ()) {
      HashMap colval = new HashMap();
      colval = (HashMap)listIt.next();
    int id;
    for(int i = 1; i <= colval.size(); i++) {
    Integer key = new Integer(i);
      String iKey = key.toString();
      if(i == 1){
      id = colval.get(iKey);
      }
      else{
%>
      <%= colval.get(iKey) %>
<%  
      }
   }
 %>
 <br>
 <%
 }
%>
</body>
</html>
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17893235
instead of  id = colval.get(iKey);

try


 id = colval.get(iKey).hashCode();
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17893311
or try this

Integer id;
                                    for(int i = 1; i <= colval.size(); i++) {
                                    Integer key = new Integer(i);
                                     String iKey = key.toString();
                                     if(i == 1){
                                     
                                     
                                     id = (Integer) colval.get(iKey);
                                     }
                                     ...
0
 

Author Comment

by:basirana
ID: 17893452
You are the one that works perfect... Thanks
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17893460
u r welcome!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question