This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HF Servlet & JSP Chapter 3 (Servlet Version 3 ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HF Servlet & JSP Chapter 3 (Servlet Version 3 )" Watch "HF Servlet & JSP Chapter 3 (Servlet Version 3 )" New topic
Author

HF Servlet & JSP Chapter 3 (Servlet Version 3 )

Sai Vikas
Greenhorn

Joined: Dec 06, 2011
Posts: 7

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

Joined: Jun 07, 2011
Posts: 208

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


OCJP-90%,OCPWCD-95%
Sai Vikas
Greenhorn

Joined: Dec 06, 2011
Posts: 7

Thanks Sagar
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HF Servlet & JSP Chapter 3 (Servlet Version 3 )