pro_java_server thread: Chp 7_AlphabetCode.class-bean + forLoop.jsp execution with error messages
Chapter 7_AlphabetCode.class-bean + forLoop.jsp execution with error
messages
I am using SUN Java Web Server 2.0 to execute the forLoop.jsp +
AlphabetCode.class-bean.
The ".jsp" file is located under the "[server]\public_html" directory and
the bean file is located under the "[server]\classes\test\" directory
The error messages I got are as follow:
Error during JSP page processing
java.lang.NoClassDefFoundError: java/util/HashMap
at test.AlphabetCode2.(Compiled Code)
at java.beans.Beans.instantiate(Beans.java:120)
at pagecompile.jsp._for2._jspService(Compiled Code)
at
com.sun.server.http.pagecompile.jsp.runtime.HttpJspBase.service(HttpJspBase.java:87)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at
com.sun.server.http.pagecompile.jsp.runtime.JspServlet.runServlet(JspServlet.java:469)
at
com.sun.server.http.pagecompile.jsp.runtime.JspServlet.processJspPage(JspServlet.java:259)
at
com.sun.server.http.pagecompile.jsp.runtime.JspServlet.service(JspServlet.java:97)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at com.sun.server.ServletState.callService(Compiled Code)
at com.sun.server.ServletManager.callServletService(Compiled Code)
at
com.sun.server.ProcessingState.invokeTargetServlet(ProcessingState.java:423)
at
com.sun.server.http.HttpProcessingState.execute(HttpProcessingState.java:79)
at com.sun.server.http.stages.Runner.process(Runner.java:79)
at com.sun.server.ProcessingSupport.process(Compiled Code)
at com.sun.server.Service.process(Service.java:204)
at
com.sun.server.http.HttpServiceHandler.handleRequest(HttpServiceHandler.java:374)
at com.sun.server.http.HttpServiceHandler.handleRequest(Compiled Code)
at com.sun.server.HandlerThread.run(Compiled Code)
The code for the JSP file (for2.jsp) are as follow:
<HTML>
<HEAD>
<TITLE>
Color demo I
</TITLE>
</HEAD>
<BODY>
<%@ page language="java" %>
<%! char d = 0; %>
<jsp:useBean id="testAlphabetCode" class="test.AlphabetCode2" scope="application"/>
<%
for(int i = 0; i < 26; i++) {
for(int j = 0; j < 26; j++) {
d = (char)(0x41 + (26 - i + j)%26);
Character thisChar = new Character(d);
testAlphabetCode.setCharacter(thisChar.toString());
%>
<FONT color= <%=testAlphabetCode.getColor()%> >
<%=testAlphabetCode.getCharacter()%>
</FONT>
<%
}
%>
<BR>
<%
}
%>
</BODY>
</HTML>
And the code for the Bean file (AlphabetCode2.class) are as follow:
package test;
import java.util.HashMap;
import java.awt.Color;
public class AlphabetCode2 {
HashMap map;
char c = 0;
Integer colorNumber;
static int FIRST_LETTER = 0x41;
static int ALPHABET_LENGTH = 26;
float s = 0.9f;
float b = 0.9f;
public AlphabetCode2() {
this.map = new HashMap(ALPHABET_LENGTH);
for(int i = 0; i < ALPHABET_LENGTH; i++) {
this.c = (char)(FIRST_LETTER + i);
float h = (float)i/ALPHABET_LENGTH;
this.map.put(new Character(c), Color.getHSBColor(h, s, b));
}
}
public void setCharacter(String nextChar) {
this.c = nextChar.charAt(0);
}
public String getCharacter() {
return (new Character(this.c).toString());
}
public String getColor() {
Color rgb = (Color)map.get(new Character(this.c));
StringBuffer htmlColor = new StringBuffer(
colorNumber.toHexString(rgb.getRGB()
&
0x00ffffff));
if (htmlColor.length() != 6) {
htmlColor.insert(0, "\"#00");
} else
htmlColor.insert(0, "\"#");
htmlColor.append("\"");
return htmlColor.toString();
}
}
I have been struggling with this for few days.
I would appreciate all kinds of comments/suggestions.
Thanks in advanceand sorry for this long posting.
JJ