JSP silently fails to compile

R

Ronald Fischer

I've got a JSP which does not compile from within tomcat. I don't get any
error message; there is a java file, but simply no class file.

I suspect some kind of internal compiler error. I narrowed the problem down
to the following observation:

The working JSP (which compiles and works fine) differs from the non-working
one only in that it contains the statement

Map parameters;

somewhere in an inner block of a while-loop. Note that the variable is
only declared, not used.

Further: When I replace this statement by

HashMap parameters;

a class file is generated, but reveals weird behaviour.

Finally: When I move the HashMap declaration to the outermost block,
withouth changing anything else, a class file is generated and works
fine.

Did anybody already experience something similar? Is there a way to
find out more of what is happening during compilation (kind of a
"verbose" feature for the JSP compiler)?

Ronald
 
C

Chris Smith

Ronald said:
I've got a JSP which does not compile from within tomcat. I don't get any
error message; there is a java file, but simply no class file.

Have you tried compiling the file by hand with javac? What happens?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
S

Sudsy

Ronald said:
I've got a JSP which does not compile from within tomcat. I don't get any
error message; there is a java file, but simply no class file.

I suspect some kind of internal compiler error. I narrowed the problem down
to the following observation:

The working JSP (which compiles and works fine) differs from the non-working
one only in that it contains the statement

Map parameters;

Map is an interface, not a class.
somewhere in an inner block of a while-loop. Note that the variable is
only declared, not used.

Further: When I replace this statement by

HashMap parameters;

a class file is generated, but reveals weird behaviour.

Like what?
Finally: When I move the HashMap declaration to the outermost block,
withouth changing anything else, a class file is generated and works
fine.

Which points to the logic in your code, right?
Did anybody already experience something similar? Is there a way to
find out more of what is happening during compilation (kind of a
"verbose" feature for the JSP compiler)?

I see lots of useful information in $TOMCAT_HOME/logs/jasper*.log
files.
 
R

Ronald Fischer

Sudsy said:
Map is an interface, not a class.

Yes, but you sure can declare a variable of an interface type. Of course
you would later have to write something like

parameters = new HashMap();
Like what?

For example, I have in the code *many* lines below the declaration
of 'parameters' two successive statements writing something to a file.
If I replace 'Map' by 'HashMap', only the first of these statements
is executed.
Which points to the logic in your code, right?

No, because the variable 'parameters' is never used anywhere in this
code. A declaration of a variable, which is not use anywhere in a block,
should not affect the logic of the program.
I see lots of useful information in $TOMCAT_HOME/logs/jasper*.log
files.

Nothing. The logs directory is empty. Could it be that I have to do something
to enable logs?

Ronald
 
P

Peter Kirk

Nothing. The logs directory is empty. Could it be that I have to do something
to enable logs?

Don't you get anything displayed on your "console window" (a stack trace or
something)?

Peter
 
S

Scott Yanoff

Ronald said:
Further: When I replace this statement by

HashMap parameters;

a class file is generated, but reveals weird behaviour.

Finally: When I move the HashMap declaration to the outermost block,
withouth changing anything else, a class file is generated and works
fine.

Just a couple of quick things to check:
Do you have the correct import statement for HashMap?
Is your declaration shown above within the <%! %> tags or the <% %> tags?

Good luck,
 
R

Ronald Fischer

Scott Yanoff said:
Do you have the correct import statement for HashMap?

Actually you got closest to what happened: There WAS an error with my
import statement. Now that I corrected it, everything runs as
expected.

In the course of tracking the bug, I learned one thing, which really
surprises me:
If I happen to write a JSP page, which somehow translates to a
syntactically
incorrect Java class, I do NOT get any feedback of what goes wrong -
no error
message, not even a message saying that there is an error at all. I
found out
what actually happened, when I looked at the directory in which the
compiler
places all java and class files from the JSP, and saw that the name of
the
generated java file (which contains an embedded versioning number) was
*newer*
than the class file, and the versioning number of these two files did
not
match either. From this I concluded that the translation of the class
file
to the java file must have failed. I tried to compile the java file
then
manually, and here I got the error message which pointed to the
incorrect import
statement.

This explained why "nothing happened" when I tried to call up my page
- the
corresponding class file was simply missing. Of course this did not
explain the
strange behaviour I encountered on one occasion, where *part* of the
JSP was
executed (as if only "half a class" file had been generated,
informally speaking),
but I did not have the nerves to investigate this further.

As you sure have guessed from my posting, I am a novice in JSP, and to
me,
the really simplest thing I expect from a "programming system" is that
I
get an error message if I write something which is not syntactically
correct.
I still remember with shudder the days of early translators of the APL
programming language, where nearly the only error message you got read
"SYNTAX ERROR". I was not aware that it can be done worse - i.e.
getting
no error message at all.

I talked with people who have a deeper understanding in JSP and
Tomcat, but
nobody could tell me some way, how I can be automatically informed of
errors
resulting from the JSP compilation process. I therefore adapt the
following strategy: If I have the impression that some page is
missing,
I try to find the name of the java file (which, due to name mangling,
involves a bit of wild guessing), and if there is no class file with
the
same name, I compile manually. In case someone knows a better way of
achieving this goal, please let me know.

Ronald
 
X

Xavier Tarrago

This is not my experience. When a jsp page contains an error, I get
exception (if I can remember) in the returned html page. I think I also get
an error in the log file.

You could delete all local cache files you browser could use in case of
error...
 
R

Ronald Fischer

Xavier Tarrago said:
This is not my experience. When a jsp page contains an error, I get
exception (if I can remember) in the returned html page.

Only if it is a run-time error.

If it is a compile-time error, there is nothing which can executed.

Just try it out...

Ronald
 
J

John C. Bollinger

Ronald said:
Only if it is a run-time error.

If it is a compile-time error, there is nothing which can executed.

No, I normally get exceptions reported by the JSP engine if compilation
fails. Is it possible that you have configured an error page for your
webapp that hangs? Or made some other configuration choice in your
server or webapp that might explain the failure to deliver an error
message to the client?


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top