Solved

Type mismatch: cannot convert from Object to HashMap

Posted on 2006-11-07
10
11,094 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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