8

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.

AegLos
  • 157
  • 1
  • 1
  • 10

4 Answers4

7

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).

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • 2
    Doesn't work. I had my imports done. I should have said that. Sorry. – AegLos May 21 '12 at 10:00
  • Try to comment the code and compile your jsp. If that works, then copy your code into another class and test it to know it runs. After that, make your all the imports you need are in your class. Also, by the description you're giving, it looks like `parser` is not even a class but looks like an attribute for a class. – Luiggi Mendoza May 21 '12 at 14:06
7

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

Burt
  • 71
  • 1
  • 2
3

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.

AegLos
  • 157
  • 1
  • 1
  • 10
1

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/

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96