Solved

Type mismatch: cannot convert from Object to HashMap

Posted on 2006-11-07
10
10,751 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A Short Story about the Best File Recovery Software – Acronis True Image 2017
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now