I have encountered a problem in the code given on page 84-85 of chapter
5 in the book Professional Java Server Programming.
The code for the listroomservlet is as follows :
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String expand = req.getParameter("expand");
HttpSession session = req.getSession();
String avatarName = (String) session.getValue("avatarName");
if (avatarName == null)
{
avatarName = "";
}
writePage(out, expand, avatarName);
out.close();
}
private void writePage(PrintWriter out, String expand, String
avatarName)
{
out.println("<HTML>");
out.println("<HEAD><TITLE>Chat rooms</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>Chat rooms</H1>");
out.println("<FORM METHOD=POST ACTION=chatroom>");
// Add radio boxes for selecting a room
out.println("Select the room you like to enter " +
"or click on a name to see the description:<P>");
roomlist rl = (roomlist) getServletContext().getAttribute("rl");
Enumeration rooms = rl.getrooms();
boolean isFirst = true;
while (rooms.hasMoreElements())
{
chatroom room = (chatroom) rooms.nextElement();
String roomName = room.getname();
out.println("<INPUT TYPE=RADIO NAME=roomName VALUE='" +
roomName + "'" +
(isFirst ? " CHECKED" : "") + ">" +
"<A HREF=listrooms?expand=" +
URLEncoder.encode(roomName) + ">" +
roomName + "</A><BR>");
isFirst = false;
// Show description if requested
if (expand != null && expand.equals(roomName))
{
out.println("<BLOCKQUOTE>");
out.println(room.getdescription());
out.println("</BLOCKQUOTE><BR>");
}
}
// Add a field for the avatar name
out.println("<P>Enter your name: ");
out.println("<INPUT NAME=avatarName VALUE='" +
avatarName + "' SIZE=30>");
// Add submit button
out.println("<P><INPUT TYPE=SUBMIT VALUE='Enter'>");
out.println("</FORM>");
out.println("</BODY></HTML>");
}
and the error that I encounter is as follows :
Chat rooms
Select the room you like to enter or click on a name to see the
description:
Error. The server encountered an unexpected condition which prevented it
from fulfilling the request.
java.lang.ClassCastException
at listroomsservlet.writePage(listroomsservlet.java, Compiled
Code)
at listroomsservlet.doGet(listroomsservlet.java:79)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at
newatlanta.servletexec.ServletExec.processServletRequest(ServletExec.java)
at
newatlanta.servletexec.ServletExec.ProcessRequest(ServletExec.java,
Compiled Code)
at
newatlanta.servletexec.ServletExec.ProcessRequest(ServletExec.java)
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html