cannot be resolved to a type (jsp + eclipse)

52,777

Solution 1

Finally it was just that the classes hadn't got the visibility atribute. I had not the public attribute for them so they could not be resolved as a type although the jsp knew where they are.

That was a JFlex/CUP problem: JFlex & CUP creates classes (analex & parser) without a visibility attribute.

Thank you for you answers. Next time I'll try to be more specific with my questions.

Solution 2

You should add the necessary import statements at the beginning of the jsp. A sample:

<%@ page import="java.util.List" %>
<%@ page import="yourpackage.parser, yourpackage.analex" %> //and on

An advice: make your classes follow the Java Code Conventions proposed by Oracle. It is a good guide to help other people to read easily your code (it will help yourself when you want to review/improve the code).

Solution 3

Clean the project,and reload the JRE as follows: Java Build Path -> Libraries -> Add Library -> JRE System Library

Solution 4

Just to add more on above answer.

JasperException is the super class of all the exceptions thrown by JSP Engine. When your run JSP first time Tomcat Engine compiles your JSP and may throw compile time error which you are getting.

Read more JasperException

where the java classes are suposed to be

Your classes should be under /WEB-INF/classes directory. By default /WEB-INF/classes and /WEB-INF/lib (Third party APIs) directory comes under CLASSPATH

So, If you have package foo.bar under src direcotry, Then your class goes at /WEB-INF/classes/foo/bar/

Share:
52,777
AegLos
Author by

AegLos

Updated on July 09, 2022

Comments

  • AegLos
    AegLos almost 2 years

    I have a jsp proyect as a presentation layer to show the result (a simple string) from a function from a java class. This class is in the src directory.

    When I try to run I get this errors:

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

    and then:

    parser cannot be resolved to a type

    My jsp code is:

    <%
            String input="ebnf a{non terminal A;}";
            Symbol tree=null;
            parser p=null;
            InputStream entrada=null;
            analex analizador;
            try{
                entrada=new ByteArrayInputStream(input.getBytes("UTF-8"));
                analizador=new analex(entrada);
                p=new parser(analizador);
                tree=p.parse();
            }catch(Exception e){
                out.println("ERROR");
            }
            finally{}
            out.println("CORRECTO");
            ConDiaCClass cdc=Singleton.getInstance();
            out.println(cdc);
    %>
    

    Actually I get the same problem with ConDiaCClass and analex classes too.

    I have not created these class with Eclipse. They are from another project but they both are placed in the src directory (where the java classes are suposed to be). It seems that the jsp cannot recognize them.