File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 202

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 )
 
Similar Threads
Another Newb failing at HF Servlets & JSP Beer Example
HTTP Status 500 - error running servlet with JSP
help needed with tomcat/requestDispatcher - example form HeadFirst servlets and jsp
error HTTP Status 500 -
Suddenly stopped working