Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Type mismatch: cannot convert from Object to HashMap

Posted on 2006-11-07
10
Medium Priority
?
11,708 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

886 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