Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF Servlet & JSP Chapter 3 (Servlet Version 3 )

 
Sai Vikas
Greenhorn
Posts: 7
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am getting the following error in the Tomcat Server

Type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to java.util.List
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.example.web.BeerSelect.doPost(BeerSelect.java:22)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to java.util.List
org.apache.jsp.result_jsp._jspService(result_jsp.java:61)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.example.web.BeerSelect.doPost(BeerSelect.java:22)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.



This is my Servlet Code :




This is my reusult.jsp code

<%@ page import="java.util.*" %>
<html>
<body>
<h1 align"center"> Beer Recommendations JSP </h1>
<p>

<%
List styles = (List)request.getAttribute("styles");
Iterator it = styles.iterator();
while(it.hasNext()){
out.println("<br> try :" + it.next());
}
%>
</body>
</html>


The servlet file was successfully compiled, please help me resolve this....
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sai Vikas wrote:request.setAttribute("styles",request);

You have set request instead of result as an attribute.
So when the request goes to result.jsp,it tries to cast request object into List

which results into exception.

Regards,
Sagar
 
Sai Vikas
Greenhorn
Posts: 7
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sagar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic