Elvira
Elvira

Reputation: 1440

ClassNotFoundException JSP

I'm having a classNotFoundException in my jsp. enter image description here

Code in my JSP:

<%@ page import="Model.Pattern" %>

<% Pattern p = new Pattern("test");%>

Can you guys tell me what's wrong with it ? I've enclosed a screenshot of the exception and the tree where the files are based.

Thanks very much.

Second error: enter image description here

Pattern class:

package Model;
import java.io.Serializable;
import java.util.ArrayList;
import java.io.File;

public class Pattern implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = -2262846250404779815L;
    private String name;
    private String allConsequences;
    private Context context;
    private String allProblems;
    private String allSolutions;
    private File diagram;

    public Pattern(String nm){
        name =nm;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public File getDiagram(){
        return diagram;
    }

    public void setDiagram(File dia){
        this.diagram = dia;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public String getAllConsequences() {
        return allConsequences;
    }

    public void setAllConsequences(String allConsequences) {
        this.allConsequences = allConsequences;
    }

    public String getAllProblems() {
        return allProblems;
    }

    public void setAllProblems(String allProblems) {
        this.allProblems = allProblems;
    }

    public String getAllSolutions() {
        return allSolutions;
    }

    public void setAllSolutions(String allSolutions){
        this.allSolutions = allSolutions;
    }

}

Upvotes: 4

Views: 2264

Answers (2)

Jean-Fran&#231;ois Savard
Jean-Fran&#231;ois Savard

Reputation: 21004

When the file is there but still throws a ClassNotFoundException this most of the times mean that the JSP could not compile.

Now looking at the error Only a type can be imported, Model.Pattern resolve to a package I'm pretty sure you want to change

<%@ page import="Model.Pattern" %>

to

<%@ page import="Model.Pattern.*" %>

Now for other people that might have the same error, and that the file does actually compile, note that sometime the cache need to be flushed.

For example with tomcat, simply delete all the files in the work directory.

Looking at your edit, it confirms that the problem is in the import. The 2 other errors only happen because Pattern was not imported. But your import seems correct to me, have you tried to flush the cache like I said ? Also you should try to re-type the import statement, maybe you accidentaly typed a control char. Another thing to try would be of deleting the deleted folders (the extracted content of the war) to make sure tomcat re-deploy them.

Upvotes: 4

cнŝdk
cнŝdk

Reputation: 32155

I think the problem here is that you have specified a constructor with parameters in your Pattern class:

public Pattern(String nm){
    name =nm;
}

In that case the default constructor need to be implemented too otherwise you can't instantiate this class, try to add it to your class:

public Pattern(){  
}

Upvotes: 2

Related Questions