Re: jsp and classpath

From: Dmytro Sheyko (dshe_at_isd.dp.ua)
Date: 04/16/04


Date: Fri, 16 Apr 2004 10:59:45 +0300


> > > I'm just started off learning a bit of jsp and jservlets. I got the
> basic
> > > setup to run. But I'm having a slight problem here.
> > >
> > > The SETUP:
> > > ***************************************
> > > G:\www\Tomcat 5.0\webapps\test\WEB-INF/classes
> > > crazyClass.java, crazyClass.class, crazyClass.jar
> > > G:\www\Tomcat 5.0\webapps\test\WEB-INF\lib
> > > catalina-root.jar
> > > ***************************************
> >
> > Move crazyClass.jar from WEB-INF/classes to WEB-INF/lib
> >
> > Web Server adds jars and zips from WEB-INF/lib into classpath of web
> > application. But not from WEB-INF/classes
> >
>
> Hey Dmytro,
>
> I tried that, and I get the same error message
> *********************************************************
> org.apache.jasper.JasperException: Unable to compile class for JSP
> An error occurred at line: 4 in the jsp file: /test.jsp
> Generated servlet error:
> [javac] Compiling 1 source file
>
> G:\www\Tomcat
> 5.0\work\Catalina\localhost\test\org\apache\jsp\test_jsp.java:52: cannot
> resolve symbol
> symbol : variable crazyClass
> location: class org.apache.jsp.test_jsp
> out.print( "at " + crazyClass.getValue() );
> ^
> 1 error
> *********************************************************

Hello Yamin,

I made a test and got the same error as you pointed.

As far as I understand, the JSP compiler treats crazyClass as a variable but
not as a class. The workaround is to put class into a package.

Consider slightly changed example:

**********************************************************************
WEB-INF\lib
     crazyClass.jar
index.jsp
**********************************************************************
<!-- index.jsp -->
<%@page import="test.crazyClass"%>
<HTML>
<BODY>
<H1><%= "Test!" %></h1><%= "at " +
java.util.Calendar.getInstance().getTime() %>
<H2><%= " Line test" %></h2><%= "at " + crazyClass.getValue() %>
</BODY>
</HTML>

**********************************************************************
// test/crazyClass.java
package test;

import java.io.*;
import java.text.*;
import java.util.*;

public class crazyClass
{
    public static int x = 0;

    public static String getValue()
    {
        x++;
        return Integer.toString(x);
    }
}
**********************************************************************



Relevant Pages

  • Re: CSWS_JAVA v2.1 - Tomcat v4.1.24 - update/upgrade Tomcat?
    ... >>error when deployed to my Tomcat installation on OpenVMS. ... type Exception report ... Unable to compile class for JSP ...
    (comp.os.vms)
  • Re: unable to compile class for JSP..
    ... org.apache.jasper.JasperException: Unable to compile class for JSP: ... I haven't changed A THING in this respect, have also not changed Tomcat ... "The generated java code and the class file for this Servlet are stored ... time I loaded this same JSP a few days ago... ...
    (comp.lang.java.help)
  • Re: Tomcat 5 Wierdness
    ... Unable to compile class for JSP ... The problem seems to be that, sometime after Tomcat 3.x and before ... WEB-INF/classes directory. ...
    (alt.os.linux.suse)
  • [LoWNOISE] Tomcat 3.2.1 ..0 DoS (WinNT)
    ... --[Jakarta-Tomcat v3.2.1 Maybe Others] ... Internal Servlet Error: ... Unable to compile class for JSP ... This info will help debug any jsp. ...
    (Bugtraq)