TheWolf
TheWolf

Reputation: 1695

JSP Imported Class Implementation Not Resolving Type

I am getting an exception in Tomcat stating the following:

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

An error occurred at line: 6 in the generated java file
Only a type can be imported. business.User resolves to a package

An error occurred at line: 12 in the jsp file: /join_email_list.jsp
User cannot be resolved to a type
9:     <body>
10:         <%@ page import="business.User" %>
11:         <%
12:             User user = (User) request.getAttribute("user");
13:             String message = (String) request.getAttribute("message");
14: 
15:             if (user == null)


An error occurred at line: 12 in the jsp file: /join_email_list.jsp
User cannot be resolved to a type
9:     <body>
10:         <%@ page import="business.User" %>
11:         <%
12:             User user = (User) request.getAttribute("user");
13:             String message = (String) request.getAttribute("message");
14: 
15:             if (user == null)


An error occurred at line: 17 in the jsp file: /join_email_list.jsp
User cannot be resolved to a type
14: 
15:             if (user == null)
16:             {
17:                 user = new User();
18:             }
19:             if (message == null)
20:             {


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:349)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    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)

A few things to point out:

First:

An error occurred at line: 6 in the generated java file
Only a type can be imported. business.User resolves to a package

This is inaccurate User is a class in the business package.

Second

User user = (User) request.getAttribute("user");

User is clearly a type, in NetBeans ctrl + space brings up all the class properties and methods.

Here is the User class:

package business;

public class User
{
    private String firstName;
    private String lastName;
    private String emailAddress;

    public User()
    {
        firstName = "";
        lastName = "";
        emailAddress = "";
    }

    public User(String first, String last, String email)
    {
        firstName = first;
        lastName = last;
        emailAddress = email;
    }

    public void setFirstName(String f)
    {
        firstName = f;
    }

    public String getFirstName()
    { 
        return firstName; 
    }

    public void setLastName(String l)
    {
        lastName = l;
    }

    public String getLastName()
    { 
        return lastName; 
    }

    public void setEmailAddress(String e)
    {
        emailAddress = e;
    }

    public String getEmailAddress()
    { 
        return emailAddress; 
    }
}

How can I resolve this? It doesn't seem as if anything is wrong. Thanks.

Upvotes: 2

Views: 3327

Answers (2)

BalusC
BalusC

Reputation: 1109695

This kind of JSP error is misleading. This is under the covers actually a NoClassDefFoundError.

In other words, the /WEB-INF/classes/business/User.class is missing.

Upvotes: 2

Raul Lapeira Herrero
Raul Lapeira Herrero

Reputation: 987

Try cleaning the project (rebuilding), it seems as if you have got a different .class file than the one you think.

Another chance is the server has got dirty or outdated compiled files, clean the server too and redeploy.

Or maybe the class is in another project in Netbeans. This guide could help you with another tipical related issues:

http://www.lady4j.com/webClient.jsp?q=classnotfoundexception

Upvotes: 2

Related Questions