• Post Reply Bookmark Topic Watch Topic
  • New Topic

error - hashtable cannot be resolved to a type error  RSS feed

 
raj kiyare
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm getting the following error while running my prog. could some one help me.

error:


type Exception report

message

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

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /dex1.jsp
Generated servlet error:
Hasthtable cannot be resolved to a type

An error occurred at line: 6 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved

An error occurred at line: 6 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved

An error occurred at line: 6 in the jsp file: /dex1.jsp
Generated servlet error:
The method getparameter(String) is undefined for the type HttpServletRequest

An error occurred at line: 9 in the jsp file: /view.jsp
Generated servlet error:
Hasthtable cannot be resolved to a type

An error occurred at line: 9 in the jsp file: /view.jsp
Generated servlet error:
Enumeraton cannot be resolved to a type

An error occurred at line: 20 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved

An error occurred at line: 20 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /dex1.jsp
Generated servlet error:
Hasthtable cannot be resolved to a type

An error occurred at line: 6 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved

An error occurred at line: 6 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved

An error occurred at line: 6 in the jsp file: /dex1.jsp
Generated servlet error:
The method getparameter(String) is undefined for the type HttpServletRequest

An error occurred at line: 9 in the jsp file: /view.jsp
Generated servlet error:
Hasthtable cannot be resolved to a type

An error occurred at line: 9 in the jsp file: /view.jsp
Generated servlet error:
Enumeraton cannot be resolved to a type

An error occurred at line: 20 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved

An error occurred at line: 20 in the jsp file: /dex1.jsp
Generated servlet error:
ht cannot be resolved


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



My files are given below
dex1.html

<br><br>
<form action = "dex1.jsp" >
<b>Name: </b> <input type = "text" name = "sname"/> <br>
<b>Age: </b> <input type = "text" name = "sage"/> <br>
<input type = "submit" name = "s" value = "Add" />
<input type = "submit" name = "s" value = "Remove" />
<input type = "submit" name = "s" value = "View" /> <br>
</form>


dex1.jsp

<%@page import = "java.util.*"%>
<%!
Hasthtable ht = new Hashtable();
%>

<%
String cap = request.getParameter("s");
if(cap.equals("Add"))
{
ht.put(request.getParameter("name"),request.getParameter("age"));
}
else if(cap.equals("Remove"))
{
ht.remove(request.getparameter("name"));
}
else
{
%>
<%@include file = "view.jsp"%>
<%
}
session.setAttribute("data",ht);
System.out.println(ht.toString());
%>

view.jsp


<%@page import = "java.util.*" errorPage="error.jsp" session= "true" %>
<html>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<%
Hasthtable ht = (Hashtable)session.getAttribute("data");
Enumeraton names = ht.keys();
while(names.hasMoreElements())
{
String name = (String)names.nextElement();
String value = (String)ht.get(name); %>
<tr>
<td><%=name%></td>
<td><%=value%></td>
</tr>
<% } %>
</table>
</body>
</html>


error.jsp


<%@page isErrorPage="true"%>
Error:
<%= exception.toString() %>
<br>
Description:
<%= exception.getMessage() %>



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66261
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlets have been discredited for almost a decade now -- time to move on. Step 1 in resolving this is to remove the Java code from the JSP and move it to a Java class.
 
raj kiyare
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have just started learning JSP. was learning about declaraton tags and scriptlets. and this was my first code. so its looks like i have a lot to learn. anyway could you please tell what was the error in my code. thanks in advance.
 
Paul Clapham
Sheriff
Posts: 22706
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error in your code was simply that you mis-spelled the words "Hashtable" and "Enumeration".
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66261
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As it stands, the most likely cause of the error is forgetting to import a class or a typo. Check all that carefully. And be aware that Hashtable is an older class that is rarely used.

As a beginner, it's important to know that putting script lets, and declarations, and Java code in a JSP is a very poor practice that has been discredited since 2002. Modern JSP uses the JSTL and EL in place of Java code.
 
raj kiyare
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Paul for letting me know the mistake. Thank you Bibeault for the information . will follow your advice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!