Solved

Type mismatch: cannot convert from Object to HashMap

Posted on 2006-11-07
10
10,984 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
  • 6
  • 4
10 Comments
 
LVL 10

Accepted Solution

by:
jaggernat earned 500 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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