aspose file tools*
The moose likes JSP and the fly likes Class cannot be resolved to a Type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Class cannot be resolved to a Type" Watch "Class cannot be resolved to a Type" New topic
Author

Class cannot be resolved to a Type

Srinivas Karthik
Greenhorn

Joined: Sep 17, 2011
Posts: 28

Hello Ranchers,

I am currently preparing for SCWCD, I am following head first servlets and jsp I am stuck at EL's(Expression Language)
This is my simple jsp
TagTest.jsp:
<%@ taglib prefix="mine" uri="DiceFunctions" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>Hai Welcome ..Jsp engine working..

Tag Test running.</h2>
${mine:roll() }
</body>
</html>

This is the java file

RoolerDemo.java:

public class RoolerDemo {
public static int roller()
{
return (int)(200);
}

}

This is the tld file:

<taglib version="2.0">
<uri>DiceFunctions</uri>
<tdlib-version>1.2</tdlib-version>

<function>
<name>roll</name>
<function-class>RoolerDemo</function-class>
<function-signature>int roller()</function-signature>

</function>
</taglib>

I am getting this exception..

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

An error occurred at line: 13 in the generated java file
RoolerDemo cannot be resolved to a type

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:313)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:300)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

And if I refresh This page I am getting this exception,

org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.TagTest_jsp
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:151)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause

java.lang.ClassNotFoundException: org.apache.jsp.TagTest_jsp
java.net.URLClassLoader$1.run(URLClassLoader.java:217)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:205)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:135)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:67)
org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:262)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:145)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

I am using JBOss 5.1.0 server and JSTL version 1.2
Please help me out friends..
Tried hard to get through this... Its very stubborn.. Help will be highly appreciated..
Thanks
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1003
    
  13

I found a couple of problems with this code even though I didn't get the same error that you posted.

First, put RoolerDemo.java in a package. Never use the default package. Don't forget to change the function-class element to the full package name.

Second, <tdlib> is not the correct element.

Third, the taglib declaration in your tld is incomplete as you haven't declared the schema.

Fix those issues and the code runs.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Srinivas Karthik
Greenhorn

Joined: Sep 17, 2011
Posts: 28

Thanks for the reply Robbins,
It was a spelling mistake I used <tlib> tag and in the book it was given that, just ignore the stuff inside <taglib > so i used only version attribute and ignored others.
And the main thing is, Packages is packaging mandatory? Is that am getting these exceptions because I din't use packages.
For the example in HFSJ till now I din't use packages anytime and it worked fine for me.
So, is the exception related to packages by anyway.. I will definitely use it..
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1003
    
  13

It's not so much that packaging is mandatory as much as it's just bad practice, so it's a habit that's best avoided. It can lead to naming collisions and you can't import a class in the default package in classes that are not also in the default package. It can also cause class loader problems and issues with using protected scope.

It's a habit that easier to avoid rather than correct it later.
Srinivas Karthik
Greenhorn

Joined: Sep 17, 2011
Posts: 28

Sure Robbins, I will start packaging everything from now where ever it's required and by the way did you get the output for my EL.
Let me know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class cannot be resolved to a Type